hdu 1010 tempter of the bone
来源:互联网 发布:网络阅卷成绩 编辑:程序博客网 时间:2024/06/05 15:04
#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>using namespace std;int n,m,k;int s[500][500],vis[500][500];int flag;int t[4][2]={{0,1},{0,-1},{1,0},{-1,0}};int ax,ay,bx,by;void dfs(int x,int y,int count){int i,mx,my;if(x==bx&&y==by){if(count==k)flag=1;return;}if(count>=k)return;if(s[x][y]!='X'){for(i=0;i<4;i++){mx=x+t[i][0];my=y+t[i][1];if(mx>=1&&mx<=n&&my>=1&&my<=m&&s[mx][my]!='X'&&!vis[mx][my]){vis[mx][my]=1;dfs(mx,my,count+1);vis[mx][my]=0;if(flag)return;}}}}int main(){while(scanf("%d%d%d",&n,&m,&k)!=EOF){//memset(vis,0,sizeof(vis));//memset(s,0,sizeof(s));int i,j,count;if(n==0&&m==0&&k==0)break;for(i=1;i<=n;i++){getchar();for(j=1;j<=m;j++){scanf("%c",&s[i][j]);if(s[i][j]=='S'){ax=i;ay=j;}if(s[i][j]=='D'){bx=i;by=j;}}}getchar();//这步也别少,会WR,无语了 memset(vis,0,sizeof(vis));if(abs(ax-bx)+abs(ay-by)>k||(ax+ay+bx+by+k)%2==1)//这一步别省略,会超时的 {printf("NO\n");continue;}count=0;flag=0;vis[ax][ay]=1;dfs(ax,ay,count);if(flag==1)printf("YES\n");elseprintf("NO\n");}return 0;}
0 0
- HDU 1010 Tempter of the Bone
- 迷宫 hdu 1010 Tempter of the Bone
- HDU 1010-Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- hdu 1010 Tempter of the Bone(深搜)
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDU-1010-Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDU 1010-Tempter of the Bone
- HDU 1010 Tempter of the Bone (DFS)
- hdu 1010 Tempter of the Bone
- HDU 1010 - Tempter of the Bone
- hdu 1010 Tempter of the Bone
- 二进制中有多少个1
- iOS图文攻略之UIView 属性
- 桶排序java版本
- Picasso分析04
- 希尔排序
- hdu 1010 tempter of the bone
- Ubuntu 14.10下部署Django到Apache服务器_
- HDU-5444 Elven Postman
- UVA - 1588 Kickdown
- 初学Service
- Data Binding (ListView)
- 【bzoj3036】绿豆蛙的归宿
- UVA - 1339 Ancient Cipher
- iOS分辨率的那些事儿 ---旧工程里使用,现在被自动布局取代了