HDU 1010 Tempter of the Bone
2011-09-04 11:08
501 查看
该题TLE了几次,后来才发现要用奇偶剪纸,如果起点到终点的步数为偶数那么不管你怎样走,步数一定为偶数;
#include<stdio.h> #include<stdlib.h> #include<string.h> char map[10][10]; int flag,M,N; int d[8]={ -1,0,0,1,1,0,0,-1 }; void DFS( int x,int y,int n,int T ) { // printf( "afsad" ); if( flag || n>=T ) return; for( int k=0;k<7&&flag==0;k+=2 ) { int dx=x+d[k],dy=y+d[k+1]; if( map[dx][dy]=='.'||map[dx][dy]=='D' ) { char c=map[dx][dy]; if( (n+1)==T ) { if( map[dx][dy]=='D' ) flag=1; return; } map[dx][dy]='X'; DFS( dx,dy,n+1,T ); map[dx][dy]=c; } } } int main() { int T,row,line,x,y; while( scanf( "%d%d%d",&N,&M,&T ),N||M||T ) { flag=0; memset( map,0,sizeof( map ) ); for( int i=1; i<=N; i++ ) { scanf( "%s",map[i]+1); } for( int i=1;i<=N; i++ ) for( int j=1; j<=M; j++ ) { if( map[i][j]=='S' ) { row=i; line=j; } if( map[i][j]=='D' ) { x=i; y=j; } } map[row][line]='X'; if( T%2==(abs(( x-row )+( y-line )))%2 )//奇偶剪枝 DFS( row,line,0,T ); if( flag ) printf( "YES\n" ); else printf( "NO\n" ); } return 0; }
相关文章推荐
- HDU 1010 Tempter of the Bone
- HDU-1010 Tempter of the Bone (dfs+剪枝)
- HDU 1010 Tempter of the Bone (ZOJ 2110) DFS+剪枝
- 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(DFS)
- HDU - 1010(Tempter of the Bone)(dfs+剪枝)
- HDU 1010 Tempter of the Bone (DFS)
- HDU 1010 Tempter of the Bone(DFS+剪枝)
- HDU 1010 Tempter of the Bone
- HDU 1010 -- Tempter of the Bone(dfs+奇偶剪枝)
- HDU 1010 Tempter of the Bone heuristic 修剪
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)
- hdu 1010 Tempter of the Bone(dfs)
- HDU 1010 Tempter of the Bone(dfs+01剪枝)
- hdu - 1010 Tempter of the Bone (dfs+奇偶性剪枝) && hdu-1015 Safecracker(简单搜索)
- HDU 题目1010 Tempter of the Bone
- hdu 1010 Tempter of the Bone