杭电OJ:1010 Tempter of the Bone
来源:互联网 发布:开奖网站源码 编辑:程序博客网 时间:2024/05/16 11:15
这是一道搜索的题目,题目很常规,需要注意的是剪枝函数,如果剪纸剪的不好就很容易超时。
AC代码:
#include <stdio.h>char maze[8][8];int n,m,t;bool success;int go[][2]={1,0,-1,0,0,1,0,-1};void DFS(int x,int y,int time){for(int i=0;i<4;i++){int nx = x + go[i][0];int ny = y + go[i][1];if(nx < 0||nx >=n||ny<0||ny>=m)continue;if(maze[nx][ny]=='X')continue;if(maze[nx][ny] == 'D'){if(time + 1 ==t){success = true;return;}else continue;}maze[nx][ny] = 'X';DFS(nx,ny,time + 1);maze[nx][ny] = '.';if(success)return;}}int main(){//freopen("1.txt","r",stdin);while(scanf("%d%d%d",&n,&m,&t)!=EOF){if(n==0&&m==0&&t==0)return 0;for(int i=0;i<n;i++){scanf("%s",maze[i]);}success = false;int sx,sy;for(int i=0;i<n;i++){for(int j=0;j<m;j++){if(maze[i][j]=='D'){sx = i;sy = j;}}}for(int i=0;i<n;i++){for(int j=0;j<m;j++){if(maze[i][j]=='S'&&(i + j)%2 ==((sx + sy)%2 + t%2)%2){maze[i][j] = 'X';DFS(i,j,0);}}}puts(success==true? "YES":"NO");}return 0;}
0 0
- 杭电OJ:1010 Tempter of the Bone
- 杭电1010-Tempter of the Bone
- 杭电 Tempter of the Bone 1010
- 杭电 1010 Tempter of the Bone
- 杭电1010---Tempter of the Bone
- 杭电 1010 Tempter of the Bone
- 【杭电】[1010]Tempter of the Bone
- 杭电1010 Tempter of the Bone
- 杭电OJ——Tempter of the Bone
- 杭电OJ(HDOJ)1010题:Tempter of the Bone(DFS,迷宫求解)
- 【杭电oj】1010 - Tempter of the Bone(dfs,奇偶剪枝,好题)
- 杭电acm1010 Tempter of the Bone
- HDU-OJ-1010 Tempter of the Bone
- 杭电 HDU 1010 Tempter of the Bone
- 杭电1010Tempter of the Bone(搜索)
- 杭电1010 Tempter of the Bone(奇偶性剪枝)
- 杭电(hdu)ACM 1010 Tempter of the Bone
- 杭电1010-Tempter of the Bone(BFS)
- u盘文件丢了怎么找回
- 滑动页面效果
- JVM调优总结(七)-典型配置举例1
- struts2自定义类型转换器:DefaultTypeConverter
- setsockopt设置socket状态
- 杭电OJ:1010 Tempter of the Bone
- UML之构件图
- C#简单文件管理器的实现
- java将文件打包成ZIP压缩文件的工具类实例
- 如何学好C++语言/C语言/
- 页面果滚动效果
- android国际化
- 线程间同步之 Mutex(mutual exclusion 互斥量)
- TDD: 解除依赖