HDU 1010 Tempter of the Bone
来源:互联网 发布:长脸男生发型 知乎 编辑:程序博客网 时间:2024/06/16 18:55
题意:S是当前点,D是门,T是时间,X是墙,点是路,问是否能在T时间内达到,如果达到输出YES否则输出NO。
思路:dfs加上奇偶剪枝
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1 0到0一定是偶数步,1到1必定是偶数步,0到1和1到0一定是奇数步,从而快速判断是否能到达
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
#include<stdio.h>
#include<string.h>
int bu[4][2]= {0,1,0,-1,1,0,-1,0},n,m,t;
int Map1[10][10];
char Map[10][10];
struct node
{
int x,y;
} S,D;
int DD;
int dfs(int x,int y,int z)
{
if(z<0)
return 0;
if(x==D.x&&y==D.y&&z==0)
{
return 1;
}
int i;
if(x%2==0&&y%2==0||(x%2==1&&y%2==1))
{
if(DD==1&&z%2==0||(DD==0&&z%2==1))
return 0;
}
else
{
if(z%2==0&&DD%2==0||(DD%2==1&&z%2==1))
return 0;
}
for(i=0; i<4; i++)
{
int aa=x+bu[i][0];
int bb=y+bu[i][1];
if(aa>=0&&aa<n&&bb>=0&&bb<m&&Map1[aa][bb]==0&&Map[aa][bb]!='X')
{
Map1[aa][bb]=1;
int cc=dfs(aa,bb,z-1);
Map1[aa][bb]=0;
if(cc)
return 1;
}
}
return 0;
}
int main()
{
int i,j;
while(scanf("%d%d%d",&n,&m,&t)!=EOF&&(n+m+t)!=0)
{
for(i=0; i<n; i++)
scanf("%s",Map[i]);
for(i=0; i<n; i++)
{
for(j=0; j<m; j++)
{
if(Map[i][j]=='S')
{
S.x=i;
S.y=j;
}
if(Map[i][j]=='D')
{
D.x=i;
D.y=j;
}
}
}
if(D.x%2==0&&D.y%2==0||(D.x%2==1&&D.y%2==1))
DD=0;
else
DD=1;
Map1[S.x][S.y]=1;
int aa=dfs(S.x,S.y,t);
if(aa)
printf("YES\n");
else
printf("NO\n");
Map1[S.x][S.y]=0;
}
return 0;
}
/*
4 4 5
S.X.
..X.
..XD
....
3 4 5
S.X.
..X.
...D
2 2 3
..
SD
3 4 5
....
SXD.
....
6 6 10
....XD
......
......
......
.X....
S.....
4 3 5
.XD
...
.X.
S..
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
- Xcode5和6共存时,如何发布应用到商店
- 【cocos2dx粒子系统】总结学习
- Spring Scope
- 通过eclipse 的axis1插件,快速开发webservice服务端和客户端
- JavaScript常用技巧( 个人整理:复习备忘)
- HDU 1010 Tempter of the Bone
- 在Android中使App快速、简单地支持新浪微博、微信、QQ、facebook等十几个主流社交平台的分享功能
- java排序之快速排序
- Unity3D研究院之Assetbundle的实战
- android 加下划线
- MyEclipse M2_REPO变量调整
- 如何在window上把你的项目提交到github
- 用Ant实现Java项目的自动构建和部署
- lucene实战