zoj2110-Tempter of the Bone
来源:互联网 发布:图像分割算法实现 编辑:程序博客网 时间:2024/06/04 18:05
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1110
题目属于dfs的基础题,但是需要剪枝,不过还是卡了很久,这也看出了自己在这方面的漏洞,而且没有注意细节,例如YES我习惯性的写成了Yes了,其次,第一次剪枝时,忘了加continue,找了好久都没找到错误。
#include<stdio.h>#include<math.h> const int maxn = 100 ;char mapp[ maxn ][ maxn ] ;int visited[ maxn ][ maxn ] ;int n , m , t ;int di , dj ;int flag ;int dis[ 4 ][ 2 ] = { -1 , 0 , 1 , 0 , 0 , 1 ,0 , -1 } ;void dfs( int si , int sj , int ti ){if( si <= 0 || sj <= 0 || si > n || sj > m )return ;if( si == di && sj == dj && ti == t ){flag = 1 ;return ;}int tmp = ( t - ti ) - fabs( si - di ) - fabs( sj - dj ) ;if( tmp < 0 || tmp % 2 )return ;for( int i = 0 ; i < 4 ; i++ ){int tmpx = si + dis[ i ][ 0 ] ;int tmpy = sj + dis[ i ][ 1 ] ;if( mapp[ tmpx ][ tmpy ] != 'X' ){mapp[ tmpx ][ tmpy ] = 'X' ;dfs( tmpx , tmpy , ti + 1 ) ;if( flag )return ;mapp[ tmpx ][ tmpy ] = '.' ; }}return ;}int main(){int i , j ;int sum ;int si , sj ;while( scanf( "%d%d%d" , &n , &m, &t ) != EOF ){if( n == 0 && m == 0 && t == 0 )break;sum = 0 ;char temp ;//scanf( "%c" , &temp ) ;getchar();for( i = 1 ; i <= n ; i++ ){for( j = 1 ; j <= m ; j++ ){scanf( "%c" , &mapp[ i ][ j ] ) ;if( mapp[ i ][ j ] == 'S'){si = i ;sj = j ;}elseif( mapp[ i ][ j ] == 'D' ){di = i ;dj = j ;}elseif( mapp[ i ][ j ] == 'X' )sum++ ; }//scanf( "%c" , &temp ) ;getchar();}if( n * m - sum <= t ){printf( "NO\n" ) ;continue ;}flag = 0 ;mapp[ si ][ sj ] = 'X' ;dfs( si , sj , 0 ) ;if( flag )printf( "YES\n" ) ;elseprintf( "NO\n" ) ;}return 0 ;}
- zoj2110-Tempter of the Bone
- ZOJ2110 Tempter of the Bone
- zoj2110 Tempter of the Bone 搜索dfs
- ZOJ2110 HDU1010 搜索 Tempter of the Bone
- Tempter of the Bone解析(回溯算法)hdu1010 zoj2110
- Tempter of the Bone 回溯法 hdu1010 zoj2110
- zoj2110 - Tempter of the Bone (DFS + 奇偶性剪枝)
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the bone
- Tempter of the Bone
- Tempter of the Bone
- android入门:zxing学习笔记(二)
- hibernate中constrained
- android入门:zxing学习笔记(三)
- 网络编程的小知识点
- android入门:zxing学习笔记(四)
- zoj2110-Tempter of the Bone
- 在java类里转换字符编码为UTF-8
- FastDFS安装使用实战二(配置篇)
- android入门:zxing学习笔记(五)
- ubuntu 下在 XAMPP 和 eclipse-php 环境下安装 XDebug
- android入门:zxing学习笔记(六)
- Linux的自旋锁struct spinlock_t的使用
- linux内核学习(6)Kbuild Makefile语法分析 .
- NDK环境搭建学习笔记