HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)
来源:互联网 发布:网络摄像头4根网线接法 编辑:程序博客网 时间:2024/05/16 08:29
第一次用奇偶剪纸,记录一下吧
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <math.h>using namespace std;class NODE{public: NODE(int x,int y,int times):x(x),y(y),times(times){}; NODE(){}; NODE(const NODE &a) { x=a.x; y=a.y; times=a.times; } bool operator == (const NODE &a) { if(x==a.x&&y==a.y&×==a.times) return true; else return false; } int x,y,times;};int row,col,times;NODE END;const char wall ='X';const char road ='.';const char start ='S';const char end = 'D';char map[10][10];int s_x,s_y;int dir_x[]={0,1,0,-1};int dir_y[]={1,0,-1,0};bool canThrough(int x,int y){ if(x>=0&&x<row&&y>=0&&y<col&&map[x][y]==road) return true; else return false;}bool _find;void dfs(int x,int y,int t){ if(_find==true|| t>=times) return ; int cut=times-t-abs(x-END.x)-abs(y-END.y); if(cut<0 || cut&1 ) return ; for(int i=0;i<4;i++) { int now_x=x+dir_x[i]; int now_y=y+dir_y[i]; int tt=t+1; if(NODE(now_x,now_y,tt)==END) { _find=true; return; } if(canThrough(now_x,now_y)) { map[now_x][now_y]=wall; dfs(now_x,now_y,tt); map[now_x][now_y]=road; } }}int main(){ //freopen("in.txt","r",stdin); while(cin>>row>>col>>times,row,col,times) { _find=false; for(int i=0;i<row;i++) { for(int j=0;j<col;j++) { cin>>map[i][j]; if(map[i][j]==start) { s_x=i; s_y=j; continue; } if(map[i][j]==end) { END=NODE(i,j,times); continue; } } } dfs(s_x,s_y,0); if(_find) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0;}
- 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 (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(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(dfs+奇偶剪枝)
- HDU 1010 Tempter of the Bone - (DFS) 奇偶剪枝
- hdu 1010 Tempter of the Bone(dfs+奇偶剪枝)
- CC2530的ZigBee应用层加入串口
- 要到看得最远的地方
- HDU 3535 AreYouBusy -- 分了组的混合背包
- PHP中替换换行符 remark 中的换行
- Z-stack 串口的使用
- HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)
- 斯坦福课程ML
- c++多态的实现原理
- 讨论个问题吧,只用MUTEX,你能实现一个写者优先的读写锁吗?
- 由浅入深探究mysql索引结构原理、性能分析与优化
- 理解JavaScript Closure
- vc6.0 MFC 单文档 静态分割窗口
- Windows Blue十一大新功能汇总 改良Win8
- android推送实时视频流到darwin流媒体服务器的思路