(HDU1010)Tempter of the Bone
2016-09-16 16:29
351 查看
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1010
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<cstdlib> #include<sstream> #include<set> #include<algorithm> #include<queue> #include<stack> #include<vector> #include<ctime> #include<fstream> #include<iomanip> using namespace std; #define M 105 int n,m,t,si,sj,ei,ej,c,wall; char ma[M][M]; int dir[4][2]={{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; void DFS(int x, int y, int time) { if (x<=0||x>n||y<=0||y>m) return; if (c) return; if (x == ei && y == ej && time == t) { if(time == t) c = 1; return; } int temp = (t - time) - abs(x - ei) - abs(y - ej); if(temp<0 || temp & 1) return; for (int i=0;i<4;i++) { int x1=x+dir[i][0]; int y1=y+dir[i][1]; if (ma[x1][y1]!='X') { ma[x1][y1]='X'; DFS(x1, y1,time+1); ma[x1][y1]='.'; } } return; } int main() { while (cin>>n>>m>>t) { if(n==0&&m==0&&t==0) break; wall = 0; for (int i = 1; i<=n; i++) { for (int j = 1; j<=m; j++) { cin>>ma[i][j]; if (ma[i][j] == 'S') { si = i; sj = j; } if (ma[i][j] == 'D') { ei = i; ej = j; } if (ma[i][j] == 'X') wall ++; } } c = 0; ma[si][sj] = 'X'; if (n * m - wall <= t) { cout<<"NO"<<endl; continue; } DFS(si, sj, 0); if (c) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
相关文章推荐
- HDU1010 Tempter of the Bone(回溯 + 剪枝)
- hdu1010 Tempter of the Bone(dfs)
- hdu1010 Tempter of the Bone
- 【奇偶剪枝】【HDU1010】Tempter of the Bone
- hdu1010---Tempter of the Bone
- ZOJ2110 HDU1010 搜索 Tempter of the Bone
- hdu1010(Tempter of the Bone)深搜+剪枝
- HDU1010 Tempter of the Bone
- ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)
- hdu1010 Tempter of the Bone
- 【奇偶剪枝】【HDU1010】Tempter of the Bone
- Tempter of the Bone---hdu1010(dfs+剪枝)
- HDU1010 Tempter of the Bone
- HDU1010 Tempter of the Bone
- ZOJ2110 HDU1010 搜索 Tempter of the Bone
- HDU1010:Tempter of the Bone(DFS)
- HDU1010 Tempter of the Bone
- hdu1010(Tempter of the Bone)
- Tempter of the Bone(HDU1010)
- hdu1010-深搜+奇偶剪枝-Tempter of the Bone