意甲冠军:

两个人在一个人(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的更多相关文章

  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. 模拟 HDOJ 4552 Running Rabbits

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

  5. HDU4452 Running Rabbits

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

  6. hdu 3282 Running Median

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

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

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

  8. 模拟 --- hdu 12878 : Fun With Fractions

    Fun With Fractions Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit ...

  9. hdu 4452

    今天模拟赛的一个模拟题: 每次看到这种题就感觉很繁琐: 这次静下心来写写,感觉还不错!就是很多错误,浪费了一点时间: 代码: #include<cstdio> #include<cs ...

随机推荐

  1. SqlServer保留几位小数的两种做法

    SqlServer保留几位小数的两种做法   数据库里的 float momey 类型,都会精确到多位小数.但有时候 我们不需要那么精确,例如,只精确到两位有效数字. 解决: 1. 使用 Round( ...

  2. HTML5 在canvas绘制一个矩形

    笔者:本笃庆军 原文地址:http://blog.csdn.net/qingdujun/article/details/32930501 一.绘制矩形 canvas使用原点(0,0)在左上角的坐标系统 ...

  3. 配置jndi服务,javax.naming.NamingException的四种情况

    1.当jndi服务没有启动,或者jndi服务的属性没有设置正确,抛出如下异常: javax.naming.CommunicationException: Can't find SerialContex ...

  4. C#判断操作系统是32位还是64位(超简单)

    由于项目需要在64位和32位系统运行,需要判断当前系统是32位还是64位. 网上很多方法,但是都感觉不是很简洁,最后发现可以使用int的长度来判断:看代码 /// <summary>    ...

  5. 【原创】leetCodeOj --- Interleaving String 解题报告

    题目地址: https://oj.leetcode.com/problems/interleaving-string/ 题目内容: Given s1, s2, s3, find whether s3  ...

  6. BP神经网络的基本原理

    2.1 BP神经网络基本原理 BP网络模型处理信息的基本原理是:输入信号Xi通过中间节点(隐层点)作用于输出节点.经过非线形变换,产生输出信号Yk,网络训练的每一个样本包含输入向量X和期望输出量t,网 ...

  7. MongoDB学习笔记-维护

    主从复制 MongoDB有主从复制技术,解决高可用和容灾问题,也就是备份. 配置主从的特点: N 个节点的集群 任何节点可作为主节点 所有写入操作都在主节点上 自动故障转移 自动恢复 数据分布式存储 ...

  8. .NET读写Excel工具Spire.Xls使用(1)入门介绍

    原文:[原创].NET读写Excel工具Spire.Xls使用(1)入门介绍 在.NET平台,操作Excel文件是一个非常常用的需求,目前比较常规的方法有以下几种: 1.Office Com组件的方式 ...

  9. Handler消息源代码分析

    public static final Looper myLooper() { return (Looper)sThreadLocal.get(); } 首先到Handler运行过程的总结: 1. L ...

  10. Codeforces 12D Ball 树形阵列模拟3排序元素

    主题链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<se ...