hdu 4740 The Donkey of Gui Zhou(dfs模拟好题)
2015-11-25 19:41
567 查看
[align=left]Problem Description[/align]
View Code
There was no donkey in the province of Gui Zhou, China. A trouble maker shipped one and put it in the forest which could be considered as an N×N grid. The coordinates of the up-left cell is (0,0) , the down-right cell is (N-1,N-1) and the cell below the up-left cell is (1,0)..... A 4×4 grid is shown below:
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<math.h> #include<algorithm> #include<queue> #include<set> #include<bitset> #include<map> #include<vector> #include<stdlib.h> #include <stack> using namespace std; #define PI acos(-1.0) #define max(a,b) (a) > (b) ? (a) : (b) #define min(a,b) (a) < (b) ? (a) : (b) #define ll long long #define eps 1e-10 #define MOD 1000000007 #define N 1006 #define inf 1e12 int n; int flag; int p,q; int dirx[]={0,1,0,-1}; int diry[]={1,0,-1,0}; int vis1 ,vis2 ; void dfs(int a,int b,int c,int x,int y,int z){ vis1[a][b]=1; vis2[x][y]=1; if(flag==1){ return; } if(a==x && b==y){ flag=1; printf("%d %d\n",a,b); return; } if(p && q){ flag=1; printf("-1\n"); return; } int aa,bb,xx,yy; if(p){ aa=a; bb=b; }else{ aa=a+dirx[c]; bb=b+diry[c]; if(aa<0 || aa>=n || bb<0 || bb>=n || vis1[aa][bb]==1){ c=(c+1)%4; aa=a+dirx[c]; bb=b+diry[c]; if(aa<0 || aa>=n || bb<0 || bb>=n || vis1[aa][bb]==1){ p=1; aa=a; bb=b; } } } if(q){ xx=x; yy=y; }else{ xx=x+dirx[z]; yy=y+diry[z]; if(xx<0 || xx>=n || yy<0 || yy>=n || vis2[xx][yy]==1){ z=(z-1+4)%4; xx=x+dirx[z]; yy=y+diry[z]; if(xx<0 || xx>=n || yy<0 || yy>=n || vis2[xx][yy]==1){ q=1; xx=x; yy=y; } } } dfs(aa,bb,c,xx,yy,z); } int main() { while(scanf("%d",&n)==1){ if(n==0){ break; } memset(vis1,0,sizeof(vis1)); memset(vis2,0,sizeof(vis2)); int a,b,c,x,y,z; scanf("%d%d%d",&a,&b,&c); scanf("%d%d%d",&x,&y,&z); if(a==x && b==y){ printf("%d %d\n",a,b); continue; } flag=0; p=q=0; dfs(a,b,c,x,y,z); } return 0; }
View Code
相关文章推荐
- UINavigationBar字体颜色
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- iOS开发小技巧:刷新UITableView
- Ant的build.xml脚本模板
- 053-18 What two statements are true regarding the recommendations received from the SQL Access Advi
- loadrunner :Insufficient records for parameter in table to provide the Vuser with unique data
- StringBuffer和StringBuilder的区别
- 【Codeforces Round 333 (Div 2)D】【线段树 or ST-RMQ 初始化78msAC】Lipshitz Sequence 若干区间询问所有子区间的答案和
- 读书笔记--UI组件
- 【bzoj1819】[JSOI]Word Query电子字典 trie+暴力
- UI第十二天:通讯录实战
- LightOJ 1048 - Conquering Keokradong(二分)
- 自定义UIButton
- Request.Item和Request.Params
- hdu5568 sequence2(dp+大数)
- BIOS锁定纯UEFI启动的解锁办法
- StringBuilder与StringBuffer的区别(转) &精简版StringBuilder,提速字符串拼接
- UIWindow & UIWindowLevel详解
- 设计模式(五)创建者模式(Builder)
- UIColor (16进制颜色、透明色使用)