Labyrinth (URAL 1033)
来源:互联网 发布:java多线程返回值 编辑:程序博客网 时间:2024/06/07 20:43
Labyrinth
Time limit: 1.0 second
Memory limit: 64 MB
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.
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
5........##..#....###.....
198
/****题目的意思是,求能面对的所有墙的面积,即求出墙有多少面,然后乘以每一面墙的面积。 对于迷宫,深度优先搜索, 但是会出现起点到达不了终点的位置,所以,进行搜索时,需要从起点搜一次,从 重点开始再搜一次。搜索时走过的路进行标记,对于每一步,其上下左右有几面墙, 就计数几次。 注意:上下左右如何实现,如下“一”处; 注意:地图数组开打一些,防止出现越界。****/#include <iostream>#include <cstdio>#include <cstring>#include <string>using namespace std;int x[4]= {1,-1,0,0};// "一"int y[4]= {0,0,1,-1};// "一" 实现上下左右控制的方法int n;char Map[35][35]= {0}; //数组开大一些int path[35][35]= {0};int ans=0;void DFS(int X,int Y){ int i; path[X][Y]=1; for(i=0; i<4; i++) { if(Map[X+x[i]][Y+y[i]]=='.'&&path[X+x[i]][Y+y[i]]==0) DFS(X+x[i],Y+y[i]); else if(Map[X+x[i]][Y+y[i]]=='#') ans++; }}void read(){ int j,k; string s; scanf("%d",&n); memset(Map,'#',sizeof(Map)); for(j=1; j<=n; j++) { cin>>s; for(k=1; k<=n; k++) Map[j][k]=s[k-1]; }}void print(){ //cout<<ans<<endl; printf("%d\n",(ans-4)*9);}int main(){ read(); DFS(1,1); if(path[n][n]==0) //如果发现终点没有走过,说明起点到达不了终点,需要从终点再搜一次 DFS(n,n); print(); return 0;}
- Labyrinth (URAL 1033)
- Ural 1033 Labyrinth(bfs)
- 【Ural 1033】 Labyrinth.(迷宫)
- ural 1033 Labyrinth
- URAL 1033 Labyrinth(DFS)
- URAL 1033 Labyrinth (DFS)
- URAL.1033 Labyrinth (DFS)
- URAL 1033|Labyrinth|搜索
- ural 1033. Labyrinth
- ural 1033. Labyrinth(dfs)
- ural 1033. Labyrinth dfs
- ural 1033. Labyrinth dfs
- URAL 1145. Rope in the Labyrinth(两次BFS啊 )
- URAL - 1145 Rope in the Labyrinth
- Labyrinth(迷宫)
- Labyrinth(枚举+DP)
- Labyrinth(深度搜索)
- Labyrinth
- 获取tomcat中web.xml中定义的环境变量(env-entry)
- Java之Servlet详解
- TP link 703N 刷openwrt+挂载USB 摄像头
- android面试题 不单单为了面试也是一次很好的学习
- 【rzxt】实例分析:u盘装系统的好处与不足
- Labyrinth (URAL 1033)
- c语言宏里面#号的作用
- Consts and Fields
- PASCAL函数过程表
- 客户/服务器程序设计模板(二)客户
- 幸运数
- PowerDesigner(PowerDesigner15.1.0.2850)下载、安装以及破解
- 通过一段汇编,加深对寄存器ESP和EBP的理解
- STL函数对象(转)