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 模拟的更多相关文章

  1. 【HDU 4452 Running Rabbits】简单模拟

    两只兔子Tom和Jerry在一个n*n的格子区域跑,分别起始于(1,1)和(n,n),有各自的速度speed(格/小时).初始方向dir(E.N.W.S)和左转周期turn(小时/次). 各自每小时往 ...

  2. HDU 4452 Running Rabbits (模拟题)

    题意: 有两只兔子,一只在左上角,一只在右上角,两只兔子有自己的移动速度(每小时),和初始移动方向. 现在有3种可能让他们转向:撞墙:移动过程中撞墙,掉头走未完成的路. 相碰: 两只兔子在K点整(即处 ...

  3. [模拟] hdu 4452 Running Rabbits

    意甲冠军: 两个人在一个人(1,1),一个人(N,N) 要人人搬家每秒的速度v.而一个s代表移动s左转方向秒 特别值得注意的是假设壁,反弹.改变方向 例如,在(1,1),采取的一个步骤,以左(1,0) ...

  4. 模拟 HDOJ 4552 Running Rabbits

    题目传送门 /* 模拟:看懂题意,主要是碰壁后的转向,笔误2次 */ #include <cstdio> #include <algorithm> #include <c ...

  5. HDU4452Running Rabbits(模拟)

    HDU4452Running Rabbits(模拟) pid=4452" target="_blank" style="">题目链接 题目大意: ...

  6. HDU4452 Running Rabbits

    涉及知识点: 1. direction数组. 2. 一一映射(哈希). Running Rabbits Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  7. HDU 5510---Bazinga(指针模拟)

    题目链接 http://acm.hdu.edu.cn/search.php?action=listproblem Problem Description Ladies and gentlemen, p ...

  8. HDU 5047 Sawtooth(大数模拟)上海赛区网赛1006

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5047 解题报告:问一个“M”型可以把一个矩形的平面最多分割成多少块. 输入是有n个“M",现 ...

  9. hdu 3282 Running Median

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3282 Running Median Description For this problem, you ...

随机推荐

  1. RocketMQ使用

    RocketMQ是阿里巴巴在2012年开源的分布式消息中间件,目前已经捐赠给Apache基金会,并于2016年11月成为 Apache 孵化项目. 中间件是一类连接软件组件和应用的计算机软件,它包括一 ...

  2. mac下PHPStorm2018.2破解教程

    1.首先安装phpstorm 2.下载JetbrainsCrack-3.1-release-enc.jar然后把这个文件放入安装phpstorm/contents/lib目录下 3.用文本编辑器打开p ...

  3. Ibatis.Net 各种配置说明学习(二)

    1.各个配置文件的配置说明 providers.config:指定数据库提供者,.Net版本等信息. xxxxx.xml:映射规则. SqlMap.config:大部分配置一般都在这里,如数据库连接等 ...

  4. No.16 selenium学习之路之异常处理

    一.常见的几种异常: SyntaxError:语法错误 NameError:试图访问的变量名不存在 IndexError:索引错误,使用的索引不存在,超出序列范围 KeyError:使用了不存在的关键 ...

  5. Javascript 跨域访问解决方案 总结

    在客户端编程语言中,如javascript和ActionScript,同源策略是一个很重要的安全理念,它在保证数据的安全性方面有着重要的意义.同 源策略规定跨域之间的脚本是隔离的,一个域的脚本不能访问 ...

  6. Python练手之爬虫

    很久没更新博客了,最近自学Python,写个在百度上爬算法题题解的爬虫,第一次写爬虫..纯当练手 慢慢来.. #coding:utf-8 ''' Created on 2016年11月22日 @aut ...

  7. 因为修改linux selinux修改错误产生的问题及解决办法

    会出现这个错误: not syncing attempted to kill init 解决办法是: 开机后一直按e 然后按这个修改: https://www.deep-silver.com/kern ...

  8. MVC设计模式一

    一:基础知识 1.mvc model view control 2.模型 是应用程序的主体部分,模型表示业务数据与业务逻辑. 一个模型可以为多个视图提供数据 提高了代码的可重用性 3.视图 用户看到的 ...

  9. 20169211《Linux内核原理与分析》 第九周作业

    一.Linux内核虚拟文件系统学习总结 Linux支持各种文件系统,Linux内核通过虚拟文件系统了对各种文件系统共性的进行抽象,并对外提供统一接口,从面向对象编程的角度来看,称为抽象文件系统更为合适 ...

  10. Redis和MySQL数据一致中出现的几种情况

    1. MySQL持久化数据,Redis只读数据 redis在启动之后,从数据库加载数据. 读请求: 不要求强一致性的读请求,走redis,要求强一致性的直接从mysql读取 写请求: 数据首先都写到数 ...