涉及知识点:

1. direction数组。

2. 一一映射(哈希)。

Running Rabbits

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1565    Accepted Submission(s): 1099

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

Source

2012 Asia JinHua Regional Contest

Recommend

zhuyuanchen520   |   We have carefully selected several similar problems for you:  55665565556455635562

Statistic | Submit | Discuss | Note

#include<stdio.h>

int dir[4][2] = {-1, 0, 0, -1, 1, 0, 0, 1};

int Map[256];
int Map1[256]; int main() {
Map['N'] = 0;
Map['W'] = 1;
Map['S'] = 2;
Map['E'] = 3;
Map1['N'] = 'W';
Map1['W'] = 'S';
Map1['S'] = 'E';
Map1['E'] = 'N';
int n;
while(~scanf("%d", &n), n) {
char d1[2], d2[2];
int s1, s2;
int t1, t2;
scanf("%s%d%d", d1, &s1, &t1);
scanf("%s%d%d", d2, &s2, &t2);
int k;
scanf("%d", &k);
int x1 = 1, y1 = 1, x2 = n, y2 = n;
for(int i = 0; i < k; i++) {
int id = Map[d1[0]];
if(!dir[id][0]) {
y1 += s1 * dir[id][1];
if(y1 <= 0) {
y1 = 2 - y1;
d1[0] = 'E';
}
if(y1 > n) {
y1 = 2 * n - y1;
d1[0] = 'W';
}
} else {
x1 += s1 * dir[id][0];
if(x1 <= 0) {
x1 = 2 - x1;
d1[0] = 'S';
}
if(x1 > n) {
x1 = 2 * n - x1;
d1[0] = 'N';
}
}
id = Map[d2[0]];
if(!dir[id][0]) {
y2 += s2 * dir[id][1];
if(y2 <= 0) {
y2 = 2 - y2;
d2[0] = 'E';
}
if(y2 > n) {
y2 = 2 * n - y2;
d2[0] = 'W';
}
} else {
x2 += s2 * dir[id][0];
if(x2 <= 0) {
x2 = 2 - x2;
d2[0] = 'S';
}
if(x2 > n) {
x2 = 2 * n - x2;
d2[0] = 'N';
}
}
if(x1 == x2 && y1 == y2) {
int tmp = d1[0];
d1[0] = d2[0];
d2[0] = tmp;
} else {
if(!((i + 1) % t1))
d1[0] = Map1[d1[0]];
if(!((i + 1) % t2))
d2[0] = Map1[d2[0]];
}
}
printf("%d %d\n%d %d\n", x1, y1, x2, y2);
}
return 0;
}

  

HDU4452 Running Rabbits的更多相关文章

  1. hdu 4452 Running Rabbits 模拟

    Running RabbitsTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  2. 模拟 HDOJ 4552 Running Rabbits

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

  3. HDU 4452 Running Rabbits (模拟题)

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

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

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

  5. [模拟] hdu 4452 Running Rabbits

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

  6. hdu-4452-Running Rabbits

    /* Running Rabbits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  7. 2012 Asia JinHua Regional Contest

    Draw Something http://acm.hdu.edu.cn/showproblem.php?pid=4450 o(n)统计输入每个数的平方和. #include<cstdio> ...

  8. Crystal Clear Applied: The Seven Properties of Running an Agile Project (转载)

    作者Alistair Cockburn, Crystal Clear的7个成功要素,写得挺好. 敏捷方法的关注点,大家可以参考,太激动所以转载了. 原文:http://www.informit.com ...

  9. Running Dubbo On Spring Boot

    Dubbo(http://dubbo.io/) 是阿里的开源的一款分布式服务框架.而Spring Boot则是Spring社区这两年致力于打造的简化Java配置的微服务框架. 利用他们各自优势,配置到 ...

随机推荐

  1. Robotium--takeScreenshot(截图)

    在Robotium中,截图的方法时调用takeScreenshot(). 但有使用你会发现明明代码里调用了solo.takeScreenshot(),但却没有截图成功,那是因为被测试的应用没有SD卡的 ...

  2. Mysql大小写敏感的问题 --转

    一.1 CREATE TABLE NAME(name VARCHAR(10)); 对这个表,缺省情况下,下面两个查询的结果是一样的: SELECT * FROM TABLE NAME WHERE na ...

  3. 二叉树(二叉链表实现)JAVA代码

      publicclassTest{       publicstaticvoid main(String[] args){           char[] ch =newchar[]{'A','B ...

  4. oracle的concat的用法

    select concat( concat( concat( ( select area_name from ec_area where area_id ), ( select area_name f ...

  5. html图像入门

    在HTML中,图像由<img>标签定义. <img>是空标签,意思是说,它只包含属性,并且没有闭合标签. 要在页面上显示图像,需要使用源属性src, src指的是"s ...

  6. Sqlserver数据库日志太大如何快速删除

    sqlserver使用在windows系统中,如果文件超上百GB了,我们还直接删除不了,这个问题我以前的apache日志就碰到过,至今还没删除呢,那么Sqlserver数据库日志太大如何快速删除呢,有 ...

  7. jquery中的this 到底是什么意思? $(this)

    如果你学过面向对象语言的话,例如JAVA,你应该明白这个this在JAVA里的意思,简单的说,谁在调用它,它就代表文谁. 那么,用到这个jquery里,也算是蛮简单的.举两个例子,一个是单个对象,一个 ...

  8. .NET Reflector 8.3.3.115 官方最新版+注册机(强大的.NET反编译工具破解版)

    Lutz Roeder’s .NET Reflector,是一个可以将以.NET Framework为基础开发出来的的DLL或EXE文件,反编译为原始程序的工具软件..NET Reflector 工具 ...

  9. Nginx配置域名跳转实例

    要求:浏览器地址栏输入qj.123.com之后,地址自动变成qj.abc.com 配置nginx跳转 server { listen 80; server_name qj.abc.com qj.123 ...

  10. java IO 实例分析

    初学java,一直搞不懂java里面的io关系,在网上找了很多大多都是给个结构图草草描述也看的不是很懂.而且没有结合到java7 的最新技术,所以自己来整理一下,有错的话请指正,也希望大家提出宝贵意见 ...