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 ...
随机推荐
- REX系统2
REX(Real Time Executive)是一个面向嵌入式应用的,简单高效的,抢先式,多任务实时操作系统,支持基于优先级的任务调度算法(支持优先级反转).它提供了任务控制,任务同步,互斥,定时器 ...
- React-Native 之 环境配置和简单使用
# 前言 学习本系列内容需要具备一定 HTML 开发基础,没有基础的朋友可以先转至 HTML快速入门(一) 学习 本人接触 React Native 时间并不是特别长,所以对其中的内容和性质了解可能会 ...
- Python_oldboy_自动化运维之路_函数,装饰器,模块,包(六)
本节内容 上节内容回顾(函数) 装饰器 模块 包 1.上节内容回顾(函数) 函数 1.为什么要用函数? 使用函数之模块化程序设计,定义一个函数就相当于定义了一个工具,需要用的话直接拿过来调用.不使用模 ...
- day05作业
一.1.switch 2.字符串 3.表达式1 4.break 5.continue 二.1.B 2.A 3.BD 4.D 5.B 6.B 7.A 8.D 9.D 10.B 三.1.√ 2.√ 3.× ...
- C/C++之static
C++的static有两种用法:面向过程程序设计中的static和面向对象程序设计中的static.前者应用于普通变量和函数,不涉及类:后者主要说明static在类中的作用. 1.面向过程设计中的st ...
- linux 系统网卡无法识别,缺少驱动
#linux网卡驱动安装# Linux设备加载 #lsmod Module Size Used by e1000e 查看硬件设备 ls /usr/share/hwdata 查看pci网卡设备 lspc ...
- mybatis中多条件判断---choose when的用法
<select id="getFunctionByPage" resultMap="FunctionRlt"> SELECT K.FUNCTION_ ...
- 20165203 实验一 Java开发环境的熟悉
实验内容及步骤 实验一 Java开发环境的熟悉-1 建立有自己学号的实验目录. 通过vim Hello.java编辑代码. 编译.运行Hello.java代码. 实验一 Java开发环境的熟悉-2 新 ...
- CF 576A 猜数
A给出一个数x,B每次猜一个y,A回答B,x是否可以被y整除,求出要猜的最小次数和需要猜的数. 枚举每个素数p,可以知道如果p^k<=n,则p^k一定需要选 Sample test(s)inpu ...
- Rookey.Frame v1.0 视频教程之三发布-框架核心思想介绍
本期发布视频: (三)Rookey.Frame v1.0框架核心思想 介绍了Rookey.Frame v1.0框架搭建的核心思想,将框架核心思想理解清楚,对框架运行就会得心应手 官方视频教程: htt ...