/*
Running Rabbits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 590 Accepted Submission(s): 417 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
简单的模拟题
*/
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
using namespace std;
#define maxn 100100
int dir[][]= {,,,-,,,-,};
int n;
void chuli1(char &c,int &s,int &x,int &y,int &tim)
{
int i;
for(i=; i<s; i++)
{
if(c=='E')
{
if(y>=n)
{
y-=dir[][];
c='W';
}
else
y+=dir[][];
}
else if(c=='W')
{
if(y<=)
{
y-=dir[][];
c='E';
}
else
y+=dir[][];
}
else if(c=='S')
{
if(x>=n)
{
x-=dir[][];
c='N';
}
else
x+=dir[][];
}
else if(c=='N')
{
if(x<=)
{
x-=dir[][];
c='S';
}
else
x+=dir[][];
}
}
tim++;
}
void chuli2(char &c)
{
if(c=='E')
c='N';
else if(c=='W')
c='S';
else if(c=='S')
c='E';
else if(c=='N')
c='W';
}
int main()
{
int s1,s2,t1,t2,x1,x2,y1,y2,k,tim1,tim2;
char c1[],c2[],tmp;
while(scanf("%d",&n),n)
{
scanf("%s%d%d",c1,&s1,&t1);
scanf("%s%d%d",c2,&s2,&t2);
scanf("%d",&k);
x1=,y1=;
x2=n,y2=n;
tim1=tim2=;
while(k--)
{
chuli1(c1[],s1,x1,y1,tim1);
chuli1(c2[],s2,x2,y2,tim2);
if(x1==x2&&y1==y2)
{
tmp=c1[];
c1[]=c2[];
c2[]=tmp;
}
else
{
if(tim1%t1==)
chuli2(c1[]);
if(tim2%t2==)
chuli2(c2[]);
}
}
printf("%d %d\n%d %d\n",x1,y1,x2,y2);
}
return ;
}

hdu-4452-Running Rabbits的更多相关文章

  1. hdu 4452 Running Rabbits 模拟

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

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

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

  3. HDU 4452 Running Rabbits (模拟题)

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

  4. [模拟] hdu 4452 Running Rabbits

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

  5. HDU4452 Running Rabbits

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

  6. 模拟 HDOJ 4552 Running Rabbits

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

  7. hdu 3282 Running Median

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

  8. HDU 3282 Running Median 动态中位数,可惜数据范围太小

    Running Median Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  9. HDU 4745 Two Rabbits (2013杭州网络赛1008,最长回文子串)

    Two Rabbits Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  10. HDU 4745 Two Rabbits 区间dp_回文序列

    题目链接: http://blog.csdn.net/scnu_jiechao/article/details/11759333 Two Rabbits Time Limit: 10000/5000 ...

随机推荐

  1. ActiveReports 报表控件官方中文入门教程 (1)-安装、激活以及产品资源

    本系列文章主要是面向初次接触 ActiveReports 产品的用户,可以帮助您在三天之内轻松的掌握ActiveReports控件的基本使用方法,包括安装.激活.创建报表.绑定数据源以及发布等内容.本 ...

  2. dstat 备忘

    http://dag.wiee.rs/home-made/dstat/#download https://github.com/dagwieers/dstat http://lhflinux.blog ...

  3. JavaMail入门第二篇 创建邮件

    JavaMail API使用javax.mail.Message类来表示一封邮件,Message类是一个抽象类,所以我们需要使用其子类javax.mail.internet.MimeMessage类来 ...

  4. C++ Qt 框架静态编译 操作记录

    谁愿意写个程式出来之后还附带一堆DLL,尤其是名字如此明显的名字. 于是在网上看了看,是需要下载源代码然后进行编译的,但是看了看别人说的编译时间,长达几个小时,瞬间就感觉不想做了.因为我还需要抓紧时间 ...

  5. R语言-妹子被追后的选择分析

    前提假设 妹子们一生中可以遇到100个追求者,追求者的优秀程度符合正态分布: 每个妹子都具备判断并比较追求者优秀程度的能力: 接受或拒绝一个追求者后永远无法后悔. 那么,问题来了 当遇到追求者时,如何 ...

  6. 如何给span设置高度宽度?

    内容提要:给Span设置高度和宽度后没有作用.本文介绍了如何如何给span设置高度宽度. CSS模型中经常用的容器是DIV和span. 给Span设置高度和宽度后没有作用. <style typ ...

  7. C# 分层 三层架构

    Hello! 三层架构↓↓↓↓↓↓ 三层架构分为:表现层(UI(User Interface)).业务逻辑层(BLL(Business Logic Layer)).数据访问层(DAL(Data Acc ...

  8. [原创]winform_PC宴会图片抽奖/文字抽奖

    14年6月 好友结婚 14年4月左右知道他们婚礼由迎宾照抽奖的环节 问我有没有可以用的抽奖软件 我网上找了一会儿,就放弃了,自己做一个更快不是? 14年6月,PC宴会图片抽奖软件成功使用 --- 操作 ...

  9. jQuery高级技巧——DOM操作篇

      页面加载之DOMReady事件 所谓domReady,也就是文档就绪,我们都知道,在操作dom时必须要在dom树加载完成后才能进行操作.如何检测DOM树已经构建完成,以下是一些实现的方式: 1.使 ...

  10. DevExpress GridControl使用方法总结

    一.如何解决单击记录整行选中的问题 View->OptionsBehavior->EditorShowMode 设置为:Click 二.如何新增一条记录 (1).gridView.AddN ...