[模拟] hdu 4452 Running Rabbits
意甲冠军:
两个人在一个人(1,1),一个人(N,N)
要人人搬家每秒的速度v。而一个s代表移动s左转方向秒
特别值得注意的是假设壁,反弹。改变方向
例如,在(1,1),采取的一个步骤,以左(1,0) 其实来(1,2)
然后假设两个人见面那么交换方向而且不再左转!
思路:
直接模拟。。
代码:
#include"cstdlib"
#include"cstdio"
#include"cstring"
#include"cmath"
#include"queue"
#include"algorithm"
#include"iostream"
using namespace std;
int move[4][2]= {{-1,0},{0,1},{1,0},{0,-1}};
int n;
struct node
{
int x,y,f;
int v,t;
};
int getfx(char x)
{
if(x=='N') return 0;
else if(x=='E') return 1;
else if(x=='S') return 2;
return 3;
}
int main()
{
while(scanf("%d",&n),n)
{
int m;
char v[2];
node a,b;
a.x=a.y=1;
b.x=b.y=n;
scanf("%s%d%d",v,&a.v,&a.t);
a.f=getfx(v[0]);
scanf("%s%d%d",v,&b.v,&b.t);
b.f=getfx(v[0]);
scanf("%d",&m);
for(int i=1; i<=m; i++)
{
int xx,yy;
xx=a.x+move[a.f][0]*a.v;
yy=a.y+move[a.f][1]*a.v;
if(xx<1||yy<1)
{
a.f=(a.f+2)%4;
if(xx<1) xx=1+move[a.f][0]*(1-xx);
else yy=1+move[a.f][1]*(1-yy);
}
if(xx>n||yy>n)
{
a.f=(a.f+2)%4;
if(xx>n) xx=n+move[a.f][0]*(xx-n);
else yy=n+move[a.f][1]*(yy-n);
}
a.x=xx;
a.y=yy;
xx=b.x+move[b.f][0]*b.v;
yy=b.y+move[b.f][1]*b.v;
if(xx<1||yy<1)
{
b.f=(b.f+2)%4;
if(xx<1) xx=1+move[b.f][0]*(1-xx);
else yy=1+move[b.f][1]*(1-yy);
}
if(xx>n||yy>n)
{
b.f=(b.f+2)%4;
if(xx>n) xx=n+move[b.f][0]*(xx-n);
else yy=n+move[b.f][1]*(yy-n);
}
b.x=xx;
b.y=yy;
if(a.x==b.x && a.y==b.y) swap(a.f,b.f); //这里特别注意 交换完不转向
else
{
if(i%a.t==0) a.f=(a.f-1+4)%4;
if(i%b.t==0) b.f=(b.f-1+4)%4;
}
}
printf("%d %d\n%d %d\n",a.x,a.y,b.x,b.y);
}
return 0;
}
版权声明:本文博主原创文章。博客,未经同意不得转载。
[模拟] hdu 4452 Running Rabbits的更多相关文章
- hdu 4452 Running Rabbits 模拟
Running RabbitsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 【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点整(即处 ...
- 模拟 HDOJ 4552 Running Rabbits
题目传送门 /* 模拟:看懂题意,主要是碰壁后的转向,笔误2次 */ #include <cstdio> #include <algorithm> #include <c ...
- HDU4452 Running Rabbits
涉及知识点: 1. direction数组. 2. 一一映射(哈希). Running Rabbits Time Limit: 2000/1000 MS (Java/Others) Memory ...
- hdu 3282 Running Median
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3282 Running Median Description For this problem, you ...
- HDU 3282 Running Median 动态中位数,可惜数据范围太小
Running Median Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- 模拟 --- hdu 12878 : Fun With Fractions
Fun With Fractions Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit ...
- hdu 4452
今天模拟赛的一个模拟题: 每次看到这种题就感觉很繁琐: 这次静下心来写写,感觉还不错!就是很多错误,浪费了一点时间: 代码: #include<cstdio> #include<cs ...
随机推荐
- session与cookie的差别
session session 的工作机制是:为每一个訪客创建一个唯一的 id (UID),并基于这个 UID 来存储变量.UID 存储在 cookie 中,或者通过 URL 进行传导. ...
- android如何使用自己定义JNI接口,以及NDK环境建设和使用的工具。
一.建筑环境: 1.需要的工具: A.cygwin (在windows下使用LINUX系统) ...
- HTML contact form with CAPTCHA
http://www.html-form-guide.com/contact-form/html-contact-form-captcha.html#codedownload
- POJ训练计划2418_Hardwood Species(Trie树)
解题报告 Tire树. #include <iostream> #include <cstring> #include <cstdio> #include < ...
- Java贪吃蛇游戏
package snake.game; import java.awt.CardLayout; import java.awt.Color; import java.awt.Graphics; i ...
- MVC Controller向View传值(ViewData与ViewBag)
近期在开发项目中,使用的是ASP.NET MVC因为之前并没有接触,对于它的传值方式有些陌生,在这里进行初步总结积累学习. 一:使用 ViewData使用: public ActionResult I ...
- jquery中的选择器01
<!doctype html> <html> <head> <meta charset="gb2312"> <title> ...
- 走进C的世界-那些年我们常犯的错---keyword相关
近期一段时间參加一些面试,发现非常多细节的问题自己已经变得非常模糊了.对一些曾经常常遇到的错误.如今也说不出原因了. 而且在编码过程中也相同犯这些错误. 特别写一个博客来记录这些我们常常遇到的错误.自 ...
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的使用方法
关于js中"window.location.href"."location.href"."parent.location.href".&qu ...
- 【Linux探索之旅】第一部分第五课:Unity桌面,人生若只如初见
内容简介 1.第一部分第五课:Unity桌面,人生若只如初见 2.第一部分第六课预告:Linux如何安装在虚拟机中 Unity桌面,人生若只如初见 不容易啊,经过了前几课的学习,我们认识了Linux是 ...