ZOJ2110 HDU1010 搜索 Tempter of the Bone
来源:互联网 发布:.win域名微信打开 编辑:程序博客网 时间:2024/06/05 19:41
传送门:Tempter 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;//剪枝1if((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;}
阅读全文
0 0
- ZOJ2110 HDU1010 搜索 Tempter of the Bone
- zoj2110 Tempter of the Bone 搜索dfs
- Tempter of the Bone解析(回溯算法)hdu1010 zoj2110
- Tempter of the Bone 回溯法 hdu1010 zoj2110
- zoj2110-Tempter of the Bone
- ZOJ2110 Tempter of the Bone
- 【搜索-DFS】hdu1010 Tempter of the Bone
- ACM 搜索 hdu1010 Tempter of the Bone
- HDU1010 Tempter of the Bone
- Tempter of the Bone hdu1010
- (hdu1010)Tempter of the Bone
- hdu1010 Tempter of the Bone
- HDU1010 Tempter of the Bone
- HDU1010 Tempter of the Bone
- HDU1010:Tempter of the Bone
- HDU1010 Tempter of the Bone
- HDU1010 Tempter of the Bone
- hdu1010(Tempter of the Bone)
- HDUOJ 2011 多项式求和
- 1051: 平方根的和
- html 常用知识点
- 2017年多校联合训练 第七场(杭二中)
- [leetcode] 31. Next Permutation
- ZOJ2110 HDU1010 搜索 Tempter of the Bone
- 单例模式
- 杭电暑期多校集训—Kolakoski
- nginx快速查看配置文件的方法
- hive之分析窗函数(二)
- 1052: 数列求和4
- Python流程控制(if,for,while)
- [设计模式](六):装饰器模式(Decorator)和代理模式(Proxy)|委托模式(Delegater )
- 致即将迈入大三的自己