杭电oj 1010
2015-12-02 09:38
337 查看
先看题目
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 94609 Accepted Submission(s): 25643
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.
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.
Output
For each test case, print in one line "YES" if the doggie can survive, or "NO" otherwise.
Sample Input
Sample Output
说多了都是泪,我把这道题目的NO看成了FALSE,然后提交的时候都是wa,我就一直在找特殊的测试用例,但是找了一晚上没有找到,第二天随便看了一下,就发现错误了,哎,以后做事要仔细一点。
言归正传,这道题目的意思就是找迷宫内找到出口,找出口,大家都会想到用DFS,我也是用DFS深度搜索,需要注意的是,找到出口的时间也就是步数是一个规定值,不能多也不能少,而且走过的地方不可以返回。下面是我的代码:
ac了
Tempter of the Bone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 94609 Accepted Submission(s): 25643
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.
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.
Output
For each test case, print in one line "YES" if the doggie can survive, or "NO" otherwise.
Sample Input
4 4 5 S.X. ..X. ..XD .... 3 4 5 S.X. ..X. ...D 0 0 0
Sample Output
NO YES
说多了都是泪,我把这道题目的NO看成了FALSE,然后提交的时候都是wa,我就一直在找特殊的测试用例,但是找了一晚上没有找到,第二天随便看了一下,就发现错误了,哎,以后做事要仔细一点。
言归正传,这道题目的意思就是找迷宫内找到出口,找出口,大家都会想到用DFS,我也是用DFS深度搜索,需要注意的是,找到出口的时间也就是步数是一个规定值,不能多也不能少,而且走过的地方不可以返回。下面是我的代码:
#include <iostream> using namespace std; char maze[10][10]; int N,M,T; bool visit[10][10]; bool flag; bool canVisit(int x,int y) { if(!visit[x][y]) return true; return false; } void dfs(int number,int x,int y) { if(number>T||flag) { return ; } else if(number==T) { if(maze[x][y]=='D') flag=true; return; } else if(maze[x][y]=='.'||maze[x][y]=='S') { visit[x][y]=true; //down if(x<N-1&&canVisit(x+1,y)) { dfs(number+1,x+1,y); } //up if(x>0&&canVisit(x-1,y)) { dfs(number+1,x-1,y); } if(y<M-1&&canVisit(x,y+1)) { dfs(number+1,x,y+1); } //left if(y>0&&canVisit(x,y-1)) { dfs(number+1,x,y-1); } visit[x][y]=false; } } int main() { int startX,startY; int i,j; while(cin>>N>>M>>T&&N&&M&&T) { for(i=0;i<N;i++) { for(j=0;j<M;j++) { cin>>maze[i][j]; visit[i][j]=false; if(maze[i][j]=='S') { startX=i; startY=j; } } } flag=false; dfs(0,startX,startY); if(flag) { cout<<"YES"<<endl; } else { cout<<"NO"<<endl; } } }
ac了
相关文章推荐
- C++派生访问说明符小记
- 树的路径覆盖
- Ubuntu15.10 亲自体验
- jquery validate自定义checkbox验证规则和样式
- websphere如何删除应用程序服务器(概要管理工具)
- Web 四种常见的POST提交数据方式
- 接口的应用场景
- 关于子窗口的透明问题
- 理解伪元素 :before 和 :after
- 如何将SQL Server表驻留内存和检测
- Idea 15 激活
- 从理论到实践,全方位认识DNS(实践篇)
- 从理论到实践,全方位认识DNS(理论篇)
- 一些值得收藏的PowerShell工具
- C/C++函数调用的几种方式
- UIImageView
- 涉足计算机视觉领域要知道的
- java中synchronized用法基本总结
- 小试MapReduce
- JDK5新特性总结