Tempter of the Bone--hdu1010--zoj2110
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Tempter of the Bone--hdu1010--zoj2110,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3679字,纯文字阅读大概需要6分钟。
内容图文
![Tempter of the Bone--hdu1010--zoj2110](/upload/InfoBanner/zyjiaocheng/1057/93f4487c83384942befe0bfd014b052c.jpg)
Tempter of the Bone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 89873 Accepted Submission(s): 24438
The maze was a rectangle with sizes N by M. There was a door in the maze. At the beginning, the door was closed and it would open at the T-th second for a short period of time (less than 1 second). Therefore the doggie had to arrive at the door on exactly the T-th second. In every second, he could move one block to one of the upper, lower, left and right neighboring blocks. Once he entered a block, the ground of this block would start to sink and disappear in the next second. He could not stay at one block for more than one second, nor could he move into a visited block. Can the poor doggie survive? Please help him.
‘X‘: a block of wall, which the doggie cannot enter;
‘S‘: the start point of the doggie;
‘D‘: the Door; or
‘.‘: an empty block.
The input is terminated with three 0‘s. This test case is not to be processed.
![技术分享](/upload/getfiles/default/2022/11/11/20221111064532873.jpg)
![技术分享](http://img.my.csdn.net/uploads/201304/23/1366696342_4669.gif)
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4usingnamespace std; 5char map[8][8]; 6int m,n,bx,by,ex,ey,step,t,flag; 7int mov[4][2]={0,1,0,-1,1,0,-1,0}; 8 9bool can(int x,int y) 10{ 11if(x<0||x>m-1||y<0||y>n-1||map[x][y]==‘X‘) 12returnfalse; 13returntrue; 14} 15void DFS(int x,int y) 16{ 1718int xx,yy,i; 19if(x==ex&&y==ey)//判断是否找到终点 20 { 21if(step==t) 22 flag=1; 23return ; 24 } 25if(step>t) 26return ; 27int dis=t-abs(ex-x)-abs(ey-y)-step; 28if(dis<0||dis&1)//奇偶剪枝 29return ; 30if(flag==1) 31return ;//当初我就是没加这一句,在hduoj上超时了,但是在zoj上能过 32for(i=0;i<4;i++) 33 { 34 xx=x+mov[i][0]; 35 yy=y+mov[i][1]; 36if(can(xx,yy)) 37 { 38 step++; 39 map[xx][yy]=‘X‘; 40 DFS(xx,yy); 41 step--; 42 map[xx][yy]=‘.‘; 43 } 44 } 45} 46int main() 47{ 48int i,j; 49while(scanf("%d%d%d",&m,&n,&t),m||n||t) 50 { 51 getchar();//吸收回车符 52for(i=0;i<m;i++) 53 { 54for(j=0;j<n;j++) 55 { 56 scanf("%c",&map[i][j]); 57if(map[i][j]==‘S‘) 58 { 59 bx=i; 60 by=j; 61 } 62if(map[i][j]==‘D‘) 63 { 64 ex=i; 65 ey=j; 66 } 67 } 68 getchar(); 69 } 70 flag=0; 71 step=0; 72int best=abs(ex-bx)+abs(ey-by); 73if((best+t)&1)//首先判断一下,如果最短路径和要走的步数奇偶性不同,就直接输出NO 74 { 75 printf("NO\n"); 76continue; 77 } 78 map[bx][by]=‘X‘; 79 DFS(bx,by);//深搜 80if(flag) 81 printf("YES\n"); 82else83 printf("NO\n"); 84 } 85return0; 86 }
下面看下修剪前后的时间差距
原文:http://www.cnblogs.com/Eric-keke/p/4715337.html
内容总结
以上是互联网集市为您收集整理的Tempter of the Bone--hdu1010--zoj2110全部内容,希望文章能够帮你解决Tempter of the Bone--hdu1010--zoj2110所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。