[模拟] 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;
}
时间: 2024-10-22 18:29:36

[模拟] hdu 4452 Running Rabbits的相关文章

hdu 4452 Running Rabbits 模拟

Running RabbitsTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1344    Accepted Submission(s): 925 Problem DescriptionRabbit Tom and rabbit Jerry are running in a field. The field is an N×N grid

模拟 HDOJ 4552 Running Rabbits

题目传送门 1 /* 2 模拟:看懂题意,主要是碰壁后的转向,笔误2次 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <vector> 8 using namespace std; 9 10 const int MAXN = 1e3 + 10; 11 const int INF = 0x3f3f3f3f; 12 struct Rabbit 13

HDU4452 Running Rabbits

涉及知识点: 1. direction数组. 2. 一一映射(哈希). Running Rabbits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1565    Accepted Submission(s): 1099 Problem Description Rabbit Tom and rabbit Jerry are runn

模拟 --- hdu 12878 : Fun With Fractions

Fun With Fractions Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 152, Accepted users: 32 Problem 12878 : No special judgement Problem description A rational number can be represented as the ratio of two integ

HDU 4745 Two Rabbits(DP)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4745 题意:n个数排成一个环.两个人AB初始时各自选定一个位置.每一轮A在顺时针方向选择一个位置,B在逆时针选择一个位置,且这两个人所选位置的数字相等,然后格子跳到新选的位置上.问最多进行多少轮?有一个限制为每次跳跃不能跨过以前自己曾经选过的格子. 思路:主要是分析问题的本质.其实就是求最长回文子列.f[i][j]为[i,j]的最长回文子列,则答案为max(f[1][i],f[i+1][n]). i

HDU4452——模拟——Running Rabbits

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

hdu 3282 Running Median

题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3282 Running Median Description For this problem, you will write a program that reads in a sequence of 32-bit signed integers. After each odd-indexed value is read, output the median (middle value) of th

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

Running Median Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3282 Description For this problem, you will write a program that reads in a sequence of 32-bit signed integers. After each odd-indexed value is read

模拟/hdu 1008 Elevator

题意 开始电梯在0层 给出n个指令,每个代表下一步停到哪层 每往上一层需要6秒,往下一层需要4秒,停止需要5秒 求总时间 分析 数据很小,模拟即可喵- Accepted Code 1 /* 2 PROBLEM:hdu1007 3 AUTHER:Nicole Lam 4 MEMO:模拟 5 */ 6 7 8 #include<cstdio> 9 using namespace std; 10 11 int main() 12 { 13 int n; 14 scanf("%d"