HDOJ 4740 - The Donkey of Gui Zhou 模拟






#define ll long long
#define oo 1000000007
#define eps 1e-5
#define MAXN 3005
#define MAXM 3000005
using namespace std;  
int face[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
bool A[1005][1005][2],f1,f2;
int main()
      int n,R1,C1,D1,R2,C2,D2,R,C;    
      while (~scanf("%d",&n) && n)
               while (f1 || f2)
                       if (R1==R2 && C1==C2) break;
                       if (f1)
                              if (R<0 || R==n || C<0 || C==n || A[R][C][0])
                                      if (D1==4) D1=0;
                                      if (R<0 || R==n || C<0 || C==n || A[R][C][0]) 
                              }else R1=R,C1=C;
                       if (f2)
                              if (R<0 || R==n || C<0 || C==n || A[R][C][1])
                                      if (D2<0) D2=3;
                                      if (R<0 || R==n || C<0 || C==n || A[R][C][1]) 
                              }else R2=R,C2=C;
               if (R1==R2 && C1==C2) printf("%d %d\n",R1,C1);
                                else printf("-1\n");
      return 0;

发布了619 篇原创文章 · 获赞 95 · 访问量 79万+

The Donkey of Gui Zhou


Problem Description 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: ![](http://acm.hdu.edu.cn/data/images/C478-1003-1.jpg) The donkey lived happily until it saw a tiger far away. The donkey had never seen a tiger ,and the tiger had never seen a donkey. Both of them were frightened and wanted to escape from each other. So they started running fast. Because they were scared, they were running in a way that didn't make any sense. Each step they moved to the next cell in their running direction, but they couldn't get out of the forest. And because they both wanted to go to new places, the donkey would never stepped into a cell which had already been visited by itself, and the tiger acted the same way. Both the donkey and the tiger ran in a random direction at the beginning and they always had the same speed. They would not change their directions until they couldn't run straight ahead any more. If they couldn't go ahead any more ,they changed their directions immediately. When changing direction, the donkey always turned right and the tiger always turned left. If they made a turn and still couldn't go ahead, they would stop running and stayed where they were, without trying to make another turn. Now given their starting positions and directions, please count whether they would meet in a cell. Input There are several test cases. In each test case: First line is an integer N, meaning that the forest is a N×N grid. The second line contains three integers R, C and D, meaning that the donkey is in the cell (R,C) when they started running, and it's original direction is D. D can be 0, 1, 2 or 3. 0 means east, 1 means south , 2 means west, and 3 means north. The third line has the same format and meaning as the second line, but it is for the tiger. The input ends with N = 0. ( 2 <= N <= 1000, 0 <= R, C < N) Output For each test case, if the donkey and the tiger would meet in a cell, print the coordinate of the cell where they meet first time. If they would never meet, print -1 instead. Sample Input 2 0 0 0 0 1 2 4 0 1 0 3 2 0 0 Sample Output -1 1 3 问答


©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客