hdu1010 dfs奇偶剪枝
来源:互联网 发布:全排列算法公式 编辑:程序博客网 时间:2024/05/16 17:30
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<cstring>#include<string>#include<cmath>using namespace std;int dx[4]={-1,1,0,0};int dy[4]={0,0,-1,1};int map[10][10]={0};int n,m,t,a1,a2,b1,b2;bool flag=0;bool dfs(int x,int y,int t1){ if(flag==1||t1==0&&x==a2&&y==b2) { flag=1; return true; } int temp=t1-abs(x-a2)-abs(y-b2); if(temp<0||temp%2) return false;<span style="color: rgb(255, 0, 0); font-family: Arial, Helvetica, sans-serif;">//temp</span><span style="color: rgb(255, 0, 0); font-family: 宋体;">必须为偶数才行</span> map[x][y]=1; int i,x0,y0; for(i=0;i<=3;i++) { x0=x+dx[i]; y0=y+dy[i]; if(x0>=1&&x0<=n&&y0>=1&&y0<=m&&!map[x0][y0]) { dfs(x0,y0,t1-1); if(flag) return true; } } map[x][y]=0;}int main(){ int i,j; char ch; while(cin>>n) { cin>>m; cin>>t; if(m==0&&n==0&&t==0) return 0; flag=0; for(i=1;i<=n;i++) for(j=1;j<=m;j++) { cin>>ch; if(ch=='S') { map[i][j]=0; a1=i; b1=j; } if(ch=='D') { map[i][j]=0; a2=i; b2=j; } if(ch=='.') map[i][j]=0; if(ch=='X') map[i][j]=1; } dfs(a1,b1,t); if(flag) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0;}
0 0
- HDU1010-奇偶剪枝(DFS)
- hdu1010 dfs奇偶剪枝
- HDU1010奇偶剪枝DFS
- HDU1010 DFS+奇偶剪枝
- HDU1010 dfs奇偶剪枝
- HDU1010 DFS+奇偶剪枝
- hdu1010(DFS + 奇偶剪枝)
- hdu1010(DFS+奇偶剪枝)
- hdu1010 (dfs+奇偶剪枝)
- hdu1010(dfs+奇偶剪枝)
- HDU1010(dfs+奇偶剪枝)
- hdu1010 dfs(奇偶剪枝,路径剪枝)
- HDU1010 奇偶剪枝 + 预先筛选 + DFS搜索
- hdu1010 经典的DFS+奇偶剪枝
- HDU1010 深搜+奇偶剪枝
- hdu1010 奇偶剪枝
- hdu1010 Tempter of the Bone(dfs+奇偶剪枝)
- hdu1010 Tempter of the Bone --DFS & 奇偶剪枝
- 如何学习CCIE
- 蓝桥杯 39级台阶
- 2016蓝桥杯假期任务之《趣味算式》
- 奇怪的分式
- 网页设计中常见的几种布局
- hdu1010 dfs奇偶剪枝
- 利用Arrays.fill()方法给二维数组设定元素值
- XML读写
- adb shell 调试君正板子
- 进程&线程
- yarrAnanitnemelEtsegraLhtK.215
- servletContext百科
- 确定性这剂毒药,你喝过没?
- Oracle错误ORA-01800——ORA-01899