编程介的小学生 2017-02-20 16:44 采纳率: 20.5%
浏览 940
已采纳

Labyrinth

Description

Administration of the labyrinth has decided to start a new season with new wallpapers. For this purpose they need a program to calculate the square of the walls inside the labyrinth. This job is just for you!

The labyrinth is represented by a matrix N*N (3 <= N <= 33, you see, '3' is a magic digit!). Some matrix cells contain a dot character ('.') that denotes an empty square. Other cells contain a diesis character ('#') that denotes a square filled by monolith block of stone wall. All squares are of the same size 3*3 meters.

The walls are constructed around the labyrinth (except for the upper left and lower right corners, which are used as entrances) and on the cells with a diesis character. No other walls are constructed. There always will be a dot character at the upper left and lower right corner cells of the input matrix.

Figure 1. The labyrinth from the input sample.

Your task is to calculate the square of visible part of the walls inside the labyrinth. In other words, the square of the walls' surface visible to a visitor of the labyrinth. Note that there's no holes to look or to move through between any two adjacent blocks of the wall. The blocks are considered to be adjacent if they touch each other in any corner. See picture for an example: visible walls inside the labyrinth are drawn with bold lines. The height of all the walls is 3 meters.
Input

The first line of the input contains the single number N. The next N lines contain N characters each. Each line describes one row of the labyrinth matrix. In each line only dot and diesis characters will be used and each line will be finished with a new line character. There will be no spaces in the input.
Output

Your program should print to the output file a single integer — the exact value of the square of the wallpaper needed.
Sample Input

5
.....
...##
..#..
..###
.....
Sample Output

198

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-02-20 17:32
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘