博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU - 4740 The Donkey of Gui Zhou
阅读量:6199 次
发布时间:2019-06-21

本文共 2747 字,大约阅读时间需要 9 分钟。

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 413    Accepted Submission(s): 165

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:
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
 

 

Source
 

 

Recommend
liuyiding
 
纯模拟,注意条件判断。
 
1 #include
2 #include
3 bool mapd[1005][1005],mapt[1005][1005]; 4 int N; 5 const int dir[]={ 0,+1, 0,-1}; 6 const int dic[]={+1, 0,-1, 0}; 7 bool ok(int r,int c){ 8 return (0<=r && r

 

转载于:https://www.cnblogs.com/gangduo-shangjinlieren/p/3325239.html

你可能感兴趣的文章
Linux netstat命令详解
查看>>
Eclipse 4.5.0 离线安装 Veloeclipse 插件
查看>>
Objective-C:继承、分类(Category、extension)、协议(protocol),个人理解,仅供参考
查看>>
创建了一个基于最短路径规划geoserver的wms服务
查看>>
Nginx 的线程池与性能剖析
查看>>
每天进步一点点——Linux文件锁编程flock
查看>>
范式的数据库具体解释
查看>>
poj 3258 River Hopscotch(二分搜索之最大化最小值)
查看>>
S性能 Sigmoid Function or Logistic Function
查看>>
SQL Server2014 哈希索引原理
查看>>
MyReport报表引擎2.6.5.0新功能
查看>>
重置Oracle密码
查看>>
DNA和纳米(Nano)Fusion技术的发展趋势
查看>>
IOS基金会_ UICollectionView简单易用
查看>>
Spring xml中进行面向切面的配置
查看>>
VBA 学习
查看>>
从12大技巧、30个案例、99个模板谈怎么写标题
查看>>
windows下一个erlang包装镜像启动
查看>>
python selenium expected_conditions使用实例
查看>>
*args和**kwargs
查看>>