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 ...
随机推荐
- linux下使用indent整理代码(代码格式化)【转】
转自:https://blog.csdn.net/jiangjingui2011/article/details/7197069 常用的设置: indent -npro -kr -i8 -ts8 -s ...
- Task多线程进行多进程
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using Sys ...
- jquery记忆笔记
1.javascript需要注意的一些问题: ①不要使用==比较,始终坚持使用===比较. false == 0; // true false === 0; // false ②NaN这个特殊的Num ...
- centos7 部署镜像仓库 harbor
=============================================== 2018/4/16_第2次修改 ccb_warlock 更新 ...
- BatchNorm caffe源码
1.计算的均值和方差是channel的 2.test/predict 或者use_global_stats的时候,直接使用moving average use_global_stats 表示是否使用全 ...
- jpql和sql的区别
项目使用jpa规范 其中既可使用面对对象查询(jpql语句) 又可使用原生sql查询; 1.(经后期验证,jpql都可以) 其中有一个区别是: jpql查询字段为空: " cr.owner ...
- Linux学习笔记:mv移动或文件重命名
mv命令是move的缩写,可以用来移动文件或者将文件改名(move (rename) files),是Linux系统下常用的命令,经常用来备份文件或者目录. 语法:mv 源文件 目标文件 视mv命令中 ...
- 20165203 实验三 敏捷开发与XP实践
20165203 实验三 敏捷开发与XP实践 任务一: 1.实验要求 实验三 敏捷开发与XP实践 (http://www.cnblogs.com/rocedu/p/4795776.html), Ecl ...
- Linux 下用 smartd 监测硬盘状况
https://blog.csdn.net/hanxuehen/article/details/6024826
- MyEclipse个性化设置
1.修改项目文件默认编码 Note:myEclipse默认的编码是GBK, 也就是未设置编码格式的文件都默认使用GBK进行编码, 而更糟糕的是JSP.JavaScriptt默认编码竟然是ISO-885 ...