hdu4452 搜索模拟 Running Rabbits (2012 Asia JinHua Regional Contest problem K)
来源:互联网 发布:金融大数据应用案例 编辑:程序博客网 时间:2024/06/06 10:39
题意:一个N*N的棋盘,N<=20,两只兔子分别在左上角和右下角。兔子会跑,有四个方向,装到墙会弹回来,兔子在整点相遇会互换方向,而且每过一定的时间,兔子就会左转,(还有些细节要仔细读题)
思路:由于棋盘很小,并且告诉你兔子的速度小于边长,所以每次跑最多撞一次强,简单了。而且兔子仅仅在整点相遇才会发生互换方向,也简单了许多,只要分别的模拟,在每个小时判断一下就好了
Running Rabbits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1543 Accepted Submission(s): 1082
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.
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.
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
4E 1 1W 1 124E 1 1W 2 154E 2 2W 3 150
Sample Output
2 23 32 12 43 14 1
Source
2012 Asia JinHua Regional Contest
#include <iostream>#include <stdio.h>#include <math.h>#include <stdlib.h>#include <string>#include <string.h>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <stack>using namespace std;typedef long long LL;const int INF=0x7fffffff;const int MAX_N=10000;//E=0,S=1,W=2,N=3int d[4][2]={0,1,1,0,0,-1,-1,0};int N,K;int F[25][25];struct node{ int speed; int dir; int turn; int x,y;};node T,J;bool cango(int x,int y){ return x<=N&&y<=N&&x>0&&y>0;}void walk(node &T){ int nx=T.x; int ny=T.y; nx+=d[T.dir][0]*T.speed; ny+=d[T.dir][1]*T.speed; if(cango(nx,ny)){ T.x=nx; T.y=ny; } else{ if(nx<=0){ T.x=abs(nx)+2; T.y=ny; T.dir=4-T.dir; } else if(nx>N){ T.x=N-(nx-N); T.y=ny; T.dir=4-T.dir; } else if(ny<=0){ T.y=abs(ny)+2; T.x=nx; T.dir=2-T.dir; } else if(ny>N){ T.y=N-(ny-N); T.x=nx; T.dir=2-T.dir; } }}void input(){ char c; scanf(" %c %d%d",&c,&T.speed,&T.turn); T.x=1; T.y=1; if(c=='E'){ T.dir=0; } else if(c=='S'){ T.dir=1; } else if(c=='W'){ T.dir=2; } else if(c=='N'){ T.dir=3; } scanf(" %c %d%d",&c,&J.speed,&J.turn); if(c=='E'){ J.dir=0; } else if(c=='S'){ J.dir=1; } else if(c=='W'){ J.dir=2; } else if(c=='N'){ J.dir=3; } J.x=N; J.y=N; scanf("%d",&K);}int main(){ while(scanf("%d",&N)&&N!=0){ input(); for(int i=1;i<=K;i++){ walk(T); walk(J); if(T.x==J.x&&T.y==J.y){ swap(T.dir,J.dir); } else{ if(i%T.turn==0)T.dir=(T.dir+4-1)%4; if(i%J.turn==0)J.dir=(J.dir+4-1)%4; } } printf("%d %d\n%d %d\n",T.x,T.y,J.x,J.y); } return 0;}
1 0
- hdu4452 搜索模拟 Running Rabbits (2012 Asia JinHua Regional Contest problem K)
- 2012 Asia JinHua Regional Contest
- HDU4452 Running Rabbits(模拟)
- 2012 Asia Hangzhou/Jinhua Regional Contest
- 2012 ACM/ICPC Asia Regional Jinhua Online
- HDU 3699 A hard Aoshu Problem 2010 Asia Fuzhou Regional Contest J题 模拟 + 搜索
- The 37th ACM/ICPC Asia Regional JinHua Site Online Contest - D(爆搜)
- hdu4430 Yukari's Birthday 2012 ACM_ICPC Asia ChangChun Regional Contest problem K
- HDU 4405 Aeroplane chess (概率DP)——2012 ACM/ICPC Asia Regional Jinhua Online
- The 2012 ACM-ICPC Asia Changchun Regional Contest(problem E)
- The 2012 ACM-ICPC Asia Changchun Regional Contest(problem B)
- The 37th ACM/ICPC Asia Regional JinHua Site Online Contest - D,F
- Asia Regional Contest, Tokyo,Problem C Shopping
- 2012 Asia ChangChun Regional Contest
- 2012 Asia Tianjin Regional Contest
- 2012 Asia Tianjin Regional Contest
- 2012 Asia Tianjin Regional Contest
- The 2015 ACM-ICPC Asia Beijing Regional Contest K A Math Problem
- 百度地图最简单的完成接口,和实例代码
- C++面向对象操作符重载:输入输出操作符
- 因为我们是OIER
- fragment获取context
- Android之倒计时实现
- hdu4452 搜索模拟 Running Rabbits (2012 Asia JinHua Regional Contest problem K)
- Python联系人(添、删、查、改)
- 她生病了,可我却不能陪伴在身边
- DOxygen for C++使用说明——添加数学公式
- 关于The import android.support.v7.app cannot be resolved
- myeclipse部署maven时,src/main/resources里面配置文件加载不到webapp下classes路径下的问题 分类: Maven Myeclipse 2014-07-11 1
- Fedora23安装以后要做的优化配置
- js内如何导入jason文件及从做好的文件内获取输入框信息,以及离子特效文件
- 自做音乐播放器涉及到的相关知识