博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1033. Labyrinth
阅读量:6121 次
发布时间:2019-06-21

本文共 3112 字,大约阅读时间需要 10 分钟。

1033. Labyrinth

Time limit: 1.0 second Memory limit: 64 MB
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.
Problem illustration
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 a single integer — the exact value of the square of the wallpaper needed.

Sample

input output
5........##..#....###.....
198
Problem Author: Vladimir Pinaev
 
Problem Source: Ural Collegiate Programming Contest '99
 
*********************************************************************
广搜
**********************************************************************
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 using namespace std;11 char s[100][100];12 int a[100][100];13 int i,j,n;14 void find(int x,int y)//广搜15 {16 if(x==0||y==0||x>n||y>n)17 return;18 if(a[x][y]==0)return;19 if(s[x][y]=='#')return;20 a[x][y]=0;21 find(x+1,y);22 find(x-1,y);23 find(x,y-1);24 find(x,y+1);25 }26 int main()27 {28 cin>>n;29 getchar();30 for(i=1;i<=n;i++)31 {32 for(j=1;j<=n;j++)33 cin>>s[i][j];34 getchar();35 }36 memset(a,255,sizeof(a));37 find(1,1);38 find(n,n);39 int ans=0;40 for(i=1;i<=n;i++)41 for(j=1;j<=n;j++)42 {43 if(a[i][j]==0)//看四周44 {45 if(a[i-1][j]==-1)ans++;46 if(a[i][j-1]==-1)ans++;47 if(a[i+1][j]==-1)ans++;48 if(a[i][j+1]==-1)ans++;49 }50 51 }52 ans-=4;53 ans*=9;54 cout<
<
View Code

 

转载于:https://www.cnblogs.com/sdau--codeants/p/3242925.html

你可能感兴趣的文章
汉字转拼音 (转)
查看>>
Machine Learning Techniques -6-Support Vector Regression
查看>>
会计基础_001
查看>>
Cordova 开发环境搭建及创建第一个app
查看>>
ajax请求拿到多条数据拼接显示在页面中
查看>>
小程序: 查看正在写的页面
查看>>
dedecms生成文档数据库崩溃 mysql daemon failed to start
查看>>
Linux的50个基本命令
查看>>
Objective-C中创建单例方法的步骤
查看>>
Jenkins持续集成环境部署
查看>>
emoji等表情符号存mysql的方法
查看>>
检查磁盘利用率并且定期发送告警邮件
查看>>
MWeb 1.4 新功能介绍二:静态博客功能增强
查看>>
linux文本模式和文本替换功能
查看>>
Windows SFTP 的安装
查看>>
摄像机与绕任意轴旋转
查看>>
rsync 服务器配置过程
查看>>
预处理、const与sizeof相关面试题
查看>>
爬虫豆瓣top250项目-开发文档
查看>>
Elasticsearch增删改查
查看>>