【HDU 4452 Running Rabbits】简单模拟
两只兔子Tom和Jerry在一个n*n的格子区域跑,分别起始于(1,1)和(n,n),有各自的速度speed(格/小时)、初始方向dir(E、N、W、S)和左转周期turn(小时/次)。
各自每小时往E、N、W、S中一个方向跑speed格,每隔turn小时左转一次(即逆时针的下一个方向)。
行走中若第i步将碰壁,则第i步及剩余步改为原方向的相反方向(即折返)。
两只兔子若在第i小时到达同一点,则交换彼此的方向再走下一小时;若相遇时有兔子恰好该左转,则放弃此次左转。
第一眼像搜索,后来发现只是简单模拟~~
#include <cstdio>
#include <algorithm>
using namespace std; struct Status
{
int x,y,d,h;//坐标,方向。当前时间
}st,sj; int n,k;
char dir_t,dir_j;
int speed_t,speed_j;
int turn_t,turn_j; void go_next(Status &s,int speed)
{
s.h++;
int cnt=;
switch(s.d)//由于speed<n,所以最多只碰壁折返一次,并且两只兔子不会在一小时内相遇两次(但其实可能在走向下一个格子的过程中遇到。。。)
{
case :
while(s.y<n&&cnt<speed){s.y++; cnt++;}
if(cnt<speed)
{
s.y-=speed-cnt;
s.d=;
}break;
case :
while(s.x>&&cnt<speed){s.x--; cnt++;}
if(cnt<speed)
{
s.x+=speed-cnt;
s.d=;
}break;
case :
while(s.y>&&cnt<speed){s.y--; cnt++;}
if(cnt<speed)
{
s.y+=speed-cnt;
s.d=;
}break;
case :
while(s.x<n&&cnt<speed){s.x++; cnt++;}
if(cnt<speed)
{
s.x-=speed-cnt;
s.d=;
}
}
} int main()
{
freopen("4452.txt","r",stdin);
while(scanf("%d",&n)!=EOF)
{
if(n==) break;
getchar();
scanf("%c",&dir_t);
scanf("%d%d",&speed_t,&turn_t);
getchar();
scanf("%c",&dir_j);
scanf("%d%d",&speed_j,&turn_j);
scanf("%d",&k); st.x=st.y=;
st.h=sj.h=;
sj.x=sj.y=n;
st.d=turn_t;
sj.d=turn_j;
switch(dir_t)
{
case 'E':st.d=;break;
case 'N':st.d=;break;
case 'W':st.d=;break;
case 'S':st.d=;break;
}
switch(dir_j)
{
case 'E':sj.d=;break;
case 'N':sj.d=;break;
case 'W':sj.d=;break;
case 'S':sj.d=;break;
} while(k--)
{
if(st.x==sj.x&&st.y==sj.y)
swap(st.d,sj.d);
else
{
if(st.h!=&&st.h%turn_t==)
st.d=(st.d+)%;
if(sj.h!=&&sj.h%turn_j==)
sj.d=(sj.d+)%;
}
go_next(st,speed_t);
go_next(sj,speed_j);
}
printf("%d %d\n",st.x,st.y);
printf("%d %d\n",sj.x,sj.y);
}
return ;
}
【HDU 4452 Running Rabbits】简单模拟的更多相关文章
- HDU 4452 Running Rabbits (模拟题)
题意: 有两只兔子,一只在左上角,一只在右上角,两只兔子有自己的移动速度(每小时),和初始移动方向. 现在有3种可能让他们转向:撞墙:移动过程中撞墙,掉头走未完成的路. 相碰: 两只兔子在K点整(即处 ...
- hdu 4452 Running Rabbits 模拟
Running RabbitsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- [模拟] hdu 4452 Running Rabbits
意甲冠军: 两个人在一个人(1,1),一个人(N,N) 要人人搬家每秒的速度v.而一个s代表移动s左转方向秒 特别值得注意的是假设壁,反弹.改变方向 例如,在(1,1),采取的一个步骤,以左(1,0) ...
- hdu 4858 容器的简单模拟
我用临接表模拟容器超时 #include<stdio.h> #include<string.h> #include<vector> using namespace ...
- HDU 4772 Zhuge Liang's Password (简单模拟题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4772 题面: Zhuge Liang's Password Time Limit: 2000/1000 ...
- 模拟 HDOJ 4552 Running Rabbits
题目传送门 /* 模拟:看懂题意,主要是碰壁后的转向,笔误2次 */ #include <cstdio> #include <algorithm> #include <c ...
- (hdu step 8.1.6)士兵队列训练问题(数据结构,简单模拟——第一次每2个去掉1个,第二次每3个去掉1个.知道队伍中的人数<=3,输出剩下的人 )
题目: 士兵队列训练问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- HDU 4509 湫湫系列故事——减肥记II (简单模拟)
题意:一天一共有1440分钟,主人公每天有n件事要做,给出这n件事开始跟结束的时间,然后让你求出,空闲的时间的总分钟数是多少. 解题报告:简单模拟,只要开个一维数组标记那个每个分钟是否是有事的就可以了 ...
- java web学习总结(二十二) -------------------简单模拟SpringMVC
在Spring MVC中,将一个普通的java类标注上Controller注解之后,再将类中的方法使用RequestMapping注解标注,那么这个普通的java类就够处理Web请求,示例代码如下: ...
随机推荐
- maven添加oracle jdbc依赖
maven添加oracle jdbc依赖 由于Oracle授权问题,Maven不提供Oracle JDBC driver,为了在Maven项目中应用Oracle JDBC driver,必须手动添加到 ...
- Xcopy参数介绍
DOS批处理命令,永远是不朽的命令,不仅功能强大,同时,速度也是最快的!但是,很多新手学习计算机,都已经遗忘了本不该忘记的批处理命令. 我们不可数典忘祖,该学习的还是要学习,不该忘记的还是不能忘记,尤 ...
- UESTC_Sea Base Exploration CDOJ 409
When the scientists explore the sea base, they use a kind of auto mobile robot, which has the missio ...
- python选择排序实现与C选择排序实现
python代码: #coding=utf-8 if __name__=="__main__": arr=[3,2,1,7,11,4,5,8] print "Before ...
- python连续爬取多个网页的图片分别保存到不同的文件夹
python连续爬取多个网页的图片分别保存到不同的文件夹 作者:vpoet mail:vpoet_sir@163.com #coding:utf-8 import urllib import ur ...
- HTML5 canvas translate() 方法
HTML5 canvas translate() 方法 translate() 方法重新映射画布上的 (0,0) 位置.
- 456. 132 Pattern
456. 132 Pattern Given an array of integers a1, a2, a3-an, judge if there exists the 132 pattern. 13 ...
- javascript模式——Flyweight
Flyweight是一种共享数据内存的模式. Flyweight模式是将一些公有属性从个人中剔除,放在共享的对象当中. 下面以一个项目实例,通过不断的改进,以显示Flyweight模式的优点. 现在我 ...
- 转:APK反编译
使用工具: CSDN上下载地址: apktool (资源文件获取) 下载 dex2jar(源码文件获取) 下载 jd-gui (源码查看) 下载 Android反编译整合工具包(最新) 下载 ...
- 【IOS学习基础】weak和strong、懒加载、循环引用
一.weak和strong 1.理解 刚开始学UI的时候,对于weak和strong的描述看得最多的就是“由ARC引入,weak相当于OC中的assign,但是weak用于修饰对象,但是他们都不会造成 ...