hdu 4452 Running Rabbits 模拟
Running Rabbits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1344 Accepted Submission(s): 925
Problem Description
Rabbit Tom and rabbit Jerry are running in a field. The field is an N×N grid. Tom starts from the up-left cell and Jerry starts from the down-right cell. The coordinate of the up-left cell is (1,1) and the coordinate of the down-right cell is (N,N)。A 4×4 field and some coordinates of its cells are shown below:
The rabbits can run in four directions (north, south, west and east) and they run at certain speed measured by cells per hour. The rabbits can't get outside of the field. If a rabbit can't run ahead any more, it will turn around and keep running. For example, in a 5×5 grid, if a rabbit is heading west with a speed of 3 cells per hour, and it is in the (3, 2) cell now, then one hour later it will get to cell (3,3) and keep heading east. For example again, if a rabbit is in the (1,3) cell and it is heading north by speed 2,then a hour latter it will get to (3,3). The rabbits start running at 0 o'clock. If two rabbits meet in the same cell at k o'clock sharp( k can be any positive integer ), Tom will change his direction into Jerry's direction, and Jerry also will change his direction into Tom's original direction. This direction changing is before the judging of whether they should turn around.
The rabbits will turn left every certain hours. For example, if Tom turns left every 2 hours, then he will turn left at 2 o'clock , 4 o'clock, 6 o'clock..etc. But if a rabbit is just about to turn left when two rabbit meet, he will forget to turn this time. Given the initial speed and directions of the two rabbits, you should figure out where are they after some time.
Input
There are several test cases.
For each test case:
The first line is an integer N, meaning that the field is an N×N grid( 2≤N≤20).
The second line describes the situation of Tom. It is in format "c s t"。c is a letter indicating the initial running direction of Tom, and it can be 'W','E','N' or 'S' standing for west, east, north or south. s is Tom's speed( 1≤s<n). t means that Tom should turn left every t hours( 1≤ t ≤1000).
The third line is about Jerry and it's in the same format as the second line.
The last line is an integer K meaning that you should calculate the position of Tom and Jerry at K o'clock( 1 ≤ K ≤ 200).
The input ends with N = 0.
Output
For each test case, print Tom's position at K o'clock in a line, and then print Jerry's position in another line. The position is described by cell coordinate.
Sample Input
4 E 1 1 W 1 1 2 4 E 1 1 W 2 1 5 4 E 2 2 W 3 1 5 0
Sample Output
2 2 3 3 2 1 2 4 3 1 4 1
题意
就是有两只喵,然后他们会在n*n的格子里面走
速度分别为s1和s2,他们分别经过t1秒和t2秒之后,会向左转
当相遇的时候,交换方向
然后问你,t秒时候,他们俩在哪儿
题解
模拟大法好!
代码
#include<cstdio>
int hash(char c)
{
if(c=='N') return ;
else if(c=='W') return ;
else if(c=='S') return ;
else return ;
}
//north 0;west 1;south 2;east 3;
struct P
{
int v,x,y,s,t;
}T,J;
int n;
void forward(P& p)
{
if(p.v==)
{
p.x-=p.s;
if(p.x<) {p.x=-p.x;p.v=;}
}
else if(p.v==)
{
p.y-=p.s;
if(p.y<) {p.y=-p.y;p.v=;}
}
else if(p.v==)
{
p.x+=p.s;
if(p.x>n) {p.x=*n-p.x;p.v=;}
}
else
{
p.y+=p.s;
if(p.y>n) {p.y=*n-p.y;p.v=;}
}
}
int main()
{
int i,k;
while(scanf("%d",&n),n)
{
T.x=T.y=;J.x=J.y=n;
char c;
getchar();scanf("%c %d%d",&c,&T.s,&T.t);T.v=hash(c);
getchar();scanf("%c %d%d",&c,&J.s,&J.t);J.v=hash(c);
scanf("%d",&k);
for(i=;i<=k;i++)
{
forward(T);forward(J);
if(T.x==J.x&&T.y==J.y)
{
int tmp=T.v;T.v=J.v;J.v=tmp;
continue;
}
if(i%T.t==)T.v=(T.v+)%;
if(i%J.t==)J.v=(J.v+)%;
}
printf("%d %d\n%d %d\n",T.x,T.y,J.x,J.y);
}
return ;
}
hdu 4452 Running Rabbits 模拟的更多相关文章
- 【HDU 4452 Running Rabbits】简单模拟
两只兔子Tom和Jerry在一个n*n的格子区域跑,分别起始于(1,1)和(n,n),有各自的速度speed(格/小时).初始方向dir(E.N.W.S)和左转周期turn(小时/次). 各自每小时往 ...
- HDU 4452 Running Rabbits (模拟题)
题意: 有两只兔子,一只在左上角,一只在右上角,两只兔子有自己的移动速度(每小时),和初始移动方向. 现在有3种可能让他们转向:撞墙:移动过程中撞墙,掉头走未完成的路. 相碰: 两只兔子在K点整(即处 ...
- [模拟] hdu 4452 Running Rabbits
意甲冠军: 两个人在一个人(1,1),一个人(N,N) 要人人搬家每秒的速度v.而一个s代表移动s左转方向秒 特别值得注意的是假设壁,反弹.改变方向 例如,在(1,1),采取的一个步骤,以左(1,0) ...
- 模拟 HDOJ 4552 Running Rabbits
题目传送门 /* 模拟:看懂题意,主要是碰壁后的转向,笔误2次 */ #include <cstdio> #include <algorithm> #include <c ...
- HDU4452Running Rabbits(模拟)
HDU4452Running Rabbits(模拟) pid=4452" target="_blank" style="">题目链接 题目大意: ...
- HDU4452 Running Rabbits
涉及知识点: 1. direction数组. 2. 一一映射(哈希). Running Rabbits Time Limit: 2000/1000 MS (Java/Others) Memory ...
- HDU 5510---Bazinga(指针模拟)
题目链接 http://acm.hdu.edu.cn/search.php?action=listproblem Problem Description Ladies and gentlemen, p ...
- HDU 5047 Sawtooth(大数模拟)上海赛区网赛1006
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5047 解题报告:问一个“M”型可以把一个矩形的平面最多分割成多少块. 输入是有n个“M",现 ...
- hdu 3282 Running Median
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3282 Running Median Description For this problem, you ...
随机推荐
- 「要买车网」免费获取汽车电商要买车网购车优惠券 - 持续更新(2016-03-12)www.fortunelab.cn
汽车电商要买车网简介 “要买车”(www.yaomaiche.com)网站是上海运图投资有限公司旗下网站,是首家真正打通交易闭环的汽车电商网站,由中国电子商务成功探索者——卜广齐于2014年10月在上 ...
- mybatis比hibernate处理速度快的原因
mybatis:是面向结果集的.当要展示的页面需要几个字段时,springmvc会提供这几个字段并将其拼接成结果集,在转化为相应的对象. hibernate:是面向对象的.要展示的页面需要某些字段时, ...
- cocos2d-x 日志...
cocos2d-x 日志... http://blog.csdn.net/themagickeyjianan/article/details/39008297http://blog.csdn.net ...
- js实现ctrl+v粘贴图片或是截图
浏览器环境:谷歌浏览器 1.ctrl+v粘贴图片都是监听paste时间实现的,复制的数据都存在clipboardData下面,虽然打印显示数据长度为0,但是还是可以获取数据的 2.打印clipboar ...
- 动态RNN和静态RNN区别
调用static_rnn实际上是生成了rnn按时间序列展开之后的图.打开tensorboard你会看到sequence_length个rnn_cell stack在一起,只不过这些cell是share ...
- day07作业
import java.util.Scanner; class SsqGame { public static void main(String[] args) { int total = 0;//买 ...
- MySQL基础 - 权限配置
为数据库创建特定的用户和密码 mysql>grant all privileges on <database>.* to '<username>'@'localhost' ...
- python_selenium自动化测试框架
设计思路 本文整理归纳以往的工作中用到的东西,现汇总成基础测试框架提供分享. 框架采用python3 + selenium3 + PO + yaml + ddt + unittest等技术编写成基础测 ...
- Java容器---Set: HashSet & TreeSet & LinkedHashSet
1.Set接口概述 Set 不保存重复的元素(如何判断元素相同呢?).如果你试图将相同对象的多个实例添加到Set中,那么它就会阻止这种重复现象. Set中最常被使用的是测试归属性,你可以 ...
- MySQL学习笔记:创建整年日期
见识到另外一种创意,惊讶! 1.创建小数据表 0-9 # 创建小数据表 DROP TABLE IF EXISTS aa_numbers_small; CREATE TABLE aa_numbers_s ...