ZOJ2110 HDU1010 搜索 Tempter of the Bone
2017-08-15 19:40
561 查看
传送门:Tempter
of the Bone
大意是给一个矩阵,叫你是否可以在给定的可走路径上不重复地走,在最后一秒走到终点。
我用了两个剪枝,且称其为简直001和剪枝002,事实证明001不要都可以,002不要也能过--||。就当练习一下剪枝。
特别是002很有用:
if( d % 2 != (Time-t) % 2 )
return false ; (d=~x+~y)
of the Bone
大意是给一个矩阵,叫你是否可以在给定的可走路径上不重复地走,在最后一秒走到终点。
我用了两个剪枝,且称其为简直001和剪枝002,事实证明001不要都可以,002不要也能过--||。就当练习一下剪枝。
特别是002很有用:
if( d % 2 != (Time-t) % 2 )
return false ; (d=~x+~y)
#include<cstdio> #include<cstdlib> #include<iostream> #include<cstring> #include<string.h> #include<cmath> using namespace std; const int INF=10000000; int dis[8][8]; char c[8][8]; int x[]={0,-1,0,1}; int y[]={1,0,-1,0}; int sx,sy; int n,m,t; int fx,fy; void _Searchdis(int xx,int yy) { for(int i=0;i<4;i++) if(xx+x[i]>=1&&xx+x[i]<=n&&yy+y[i]>=1&&yy+y[i]<=m) if(c[xx+x[i]][yy+y[i]]!='X') if(dis[xx][yy]+1<dis[xx+x[i]][yy+y[i]]){ dis[xx+x[i]][yy+y[i]]=dis[xx][yy]+1; _Searchdis(xx+x[i],yy+y[i]); } return ; } bool _BFS(int xx,int yy,int steps) { if(xx==sx&&yy==sy&&steps==t) return true; if(steps+dis[xx][yy]>t) return false;//剪枝1 if((abs(xx-sx)+abs(yy-sy))%2!=abs(t-steps)%2) return false;//剪枝2 for(int i=0;i<4;i++) if(xx+x[i]>=1&&xx+x[i]<=n&&yy+y[i]>=1&&yy+y[i]<=m) if(c[xx+x[i]][yy+y[i]]!='X') { c[xx+x[i]][yy+y[i]]='X'; if(_BFS(xx+x[i],yy+y[i],steps+1)) return true; c[xx+x[i]][yy+y[i]]='.'; } return false; } int main() { int i,j; while(scanf("%d%d%d",&n,&m,&t)&&(n||m||t)) { for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++) { cin>>c[i][j]; if(c[i][j]=='D'){ sx=i;sy=j;} if(c[i][j]=='S'){ fx=i;fy=j;} dis[i][j]=INF; } } dis[sx][sy]=0; _Searchdis(sx,sy); c[fx][fy]='X';//不要搞忘 if(_BFS(fx,fy,0)) printf("YES\n"); else printf("NO\n"); } return 0; }
相关文章推荐
- ZOJ2110 HDU1010 搜索 Tempter of the Bone
- ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)
- ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)
- ZOJ-2110 Tempter of the Bone( 搜索,奇偶性剪枝)
- Tempter of the Bone 回溯法 hdu1010 zoj2110
- zoj 2110 Tempter of the Bone
- Tempter of the Bone_ZOJ 2110
- ZOJ 2110 Tempter of the Bone
- Hdu1010 - Tempter of the Bone - 深度优先搜索
- HDU 1010 ZOJ 2110 Tempter of the Bone (DFS 奇偶剪枝)
- zoj 2110 Tempter of the Bone (dfs)
- zoj(2110)Tempter of the Bone(DFS+奇偶剪枝)
- HDU 1010 && ZOJ 2110--Tempter of the Bone【DFS && 奇偶剪枝】
- zoj 2110 Tempter of the Bone
- ZOJ 2110 ( HDU 1010 ) Tempter of the Bone( 比较经典的DFS) --from lanshui_Yang
- ZOJ 2110 Tempter of the Bone
- zoj 2110 Tempter of the Bone ——DFS+剪枝
- hdu1010 Tempter of the Bone dfs搜索 剪枝
- ZOJ 2110 Tempter of the Bone
- ZOJ 2110 Tempter of the Bone