Tempter of the Bone(路径搜索)
来源:互联网 发布:idea java log4j使用 编辑:程序博客网 时间:2024/06/06 20:22
Tempter of the Bone
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 4 Accepted Submission(s) : 1
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a trap, and he tried desperately to get out of this maze.
The maze was a rectangle with sizes N by M. There was a door in the maze. At the beginning, the door was closed and it would open at the T-th second for a short period of time (less than 1 second). Therefore the doggie had to arrive at the door on exactly the T-th second. In every second, he could move one block to one of the upper, lower, left and right neighboring blocks. Once he entered a block, the ground of this block would start to sink and disappear in the next second. He could not stay at one block for more than one second, nor could he move into a visited block. Can the poor doggie survive? Please help him.
The maze was a rectangle with sizes N by M. There was a door in the maze. At the beginning, the door was closed and it would open at the T-th second for a short period of time (less than 1 second). Therefore the doggie had to arrive at the door on exactly the T-th second. In every second, he could move one block to one of the upper, lower, left and right neighboring blocks. Once he entered a block, the ground of this block would start to sink and disappear in the next second. He could not stay at one block for more than one second, nor could he move into a visited block. Can the poor doggie survive? Please help him.
Input
The input consists of multiple test cases. The first line of each test case contains three integers N, M, and T (1 < N, M < 7; 0 < T < 50), which denote the sizes of the maze and the time at which the door will open, respectively. The next N lines give the maze layout, with each line containing M characters. A character is one of the following:
'X': a block of wall, which the doggie cannot enter;
'S': the start point of the doggie;
'D': the Door; or
'.': an empty block.
The input is terminated with three 0's. This test case is not to be processed.
'X': a block of wall, which the doggie cannot enter;
'S': the start point of the doggie;
'D': the Door; or
'.': an empty block.
The input is terminated with three 0's. This test case is not to be processed.
Output
For each test case, print in one line "YES" if the doggie can survive, or "NO" otherwise.
Sample Input
4 4 5S.X...X...XD....3 4 5S.X...X....D0 0 0
Sample Output
NOYES
代码:
#include<iostream>#include<string.h>using namespace std;char map[8][8],f[8][8];int X,Z[8][8];int check(char f[8][8],int i,int j,int sum,int t)//搜索{char s1[8][8],s2[8][8],s3[8][8],s4[8][8];int a,b,x;if(sum==t&&f[i][j]=='D'||X==1){X=1;return 0;}if(f[i][j]=='X'||f[i][j]=='D'||sum>=t) return 0;else {f[i][j]='X';for(a=0;a<8;a++)for(b=0;b<8;b++)s1[a][b]=s2[a][b]=s3[a][b]=s4[a][b]=f[a][b];if(i+1<8) check(s1,i+1,j,sum+1,t);//下if(i-1>=1&&X!=1) check(s2,i-1,j,sum+1,t);//上if(j+1<8&&X!=1) check(s3,i,j+1,sum+1,t);//->if(j-1>=1&&X!=1) check(s4,i,j-1,sum+1,t);//<-}}int main(){int n,m,t,i,j,x,starti,startj,endi,endj,time;while(cin>>n>>m>>t){if(n==0&&m==0&&t==0) break;for(i=0;i<8;i++)for(j=0;j<8;j++){map[i][j]='X';Z[i][j]=(i+j)%2;//用于判断奇数偶数步,进行优化}time=0;for(i=1;i<=n;i++)for(j=1;j<=m;j++){cin>>map[i][j];if(map[i][j]=='.') time++;else if(map[i][j]=='S') starti=i,startj=j;else if(map[i][j]=='D') endi=i,endj=j;}/*进行优化否则超时(奇偶数优化和步数限制)*/if(t%2==0&&(Z[starti][startj]!=Z[endi][endj])||t%2==1&&Z[starti][startj]==Z[endi][endj]||time+1<t)cout<<"NO"<<endl;else{X=0;//X==1则可逃脱check(map,starti,startj,0,t);if(X==1) cout<<"YES"<<endl;else cout<<"NO"<<endl;}}return 0;}
0 0
- Tempter of the Bone(路径搜索)
- 搜索之Tempter of the Bone
- HDU 1010 Tempter of the Bone (搜索)
- hdu 1010 Tempter of the Bone 搜索
- zoj2110 Tempter of the Bone 搜索dfs
- 【搜索-DFS】hdu1010 Tempter of the Bone
- ACM 搜索 hdu1010 Tempter of the Bone
- Tempter of the Bone(搜索)
- tempter of the bone(搜索+剪纸)
- Tempter of the Bone(深度搜索)
- ZOJ2110 HDU1010 搜索 Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- 代理模式
- 向Dialog中加入String[]数组
- 腾讯面试题(统计数字出现的次数问题)
- Pow(x, n)
- [c.y.j]js freemarker 去除空格
- Tempter of the Bone(路径搜索)
- ios学习——网络操作
- 大河白银早评[2014年4月28日]
- APNS提供了两项基本的服务:消息推送和反馈服务
- ubuntu杂谈(一)----- ubuntu14.04 上安装ffmpeg
- 一直相信,每个人心里都住着一座城,那里生长着一片属于自己的原始森林,无论岁月如何侵蚀打磨
- 矩阵快速幂(特殊矩阵+优化)upc2604
- Linux软连接和硬链接
- QT:This application has failed to start because the application configuration is incorrect...