hdu4452 Running Rabbit

5 篇文章 0 订阅

模拟每一步Tom和Jerry 的行动

注意相遇和转弯判断的先后顺序


#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <string>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <fstream>
using namespace std;
//LOOP
#define FF(i, a, b) for(int i = (a); i < (b); ++i)
#define FD(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define FE(i, a, b) for(int i = (a); i <= (b); ++i)
#define FED(i, b, a) for(int i = (b); i>= (a); --i)
#define REP(i, N) for(int i = 0; i < (N); ++i)
#define CLR(A,value) memset(A,value,sizeof(A))
//OTHER
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define all(x) (x).begin(),(x).end()
#define EQ(a, b) (fabs((a) - (b)) <= 1e-10)
//INPUT
#define RI(n) scanf("%d", &n)
#define RII(n, m) scanf("%d%d", &n, &m)
#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)
#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)
#define RS(s) scanf("%s", s)
//OUTPUT
#define WI(n) printf("%d\n", n)
#define WS(n) printf("%s\n", n)

typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> VI;
const int INF = 1000000000;
const double eps = 1e-10;
const int MOD = 100000007;
const int MAXN = 25;

const int w = 0, s = 1, e = 2, n  = 3;
int N, K;
int dir[][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};

struct node{
    int c, s, t;
    int x, y;
}tom, jer;

void read(node& a)
{
    int x, y, z;
    char dir[29];
    RS(dir);
    RII(x, y);
    if (dir[0] == 'E') a.c = e;
    else if (dir[0] == 'W') a.c = w;
    else if (dir[0] == 'N') a.c = n;
    else a.c = s;
    a.s = x, a.t = y;
}

void getcord(node& a)
{
    a.x += dir[a.c][0];
    a.y += dir[a.c][1];
}

void bound(node& a)
{
    if (a.c == n && a.x == 1)
        a.c = s;
    if (a.c == w && a.y == 1)
        a.c = e;
    if (a.c == s && a.x == N)
        a.c = n;
    if (a.c == e && a.y == N)
        a.c = w;
}

void turn(node& a, int tm)
{
    if (tm % a.t == 0)
    {
        a.c++;
        a.c %= 4;
    }
}

void solve(int tm)
{
    bool meet = false;
    REP(i, tom.s)
    {
        bound(tom);
        getcord(tom);
    }
    REP(i, jer.s)
    {
        bound(jer);
        getcord(jer);

    }
    if (tom.x == jer.x && tom.y == jer.y)
    {
        meet = 1;
        int t = tom.c;
        tom.c = jer.c, jer.c = t;
    }
    if (!meet)
    {
        turn(tom, tm);
        turn(jer, tm);
    }
    bound(tom), bound(jer);
}

int main()
{

    while (RI(N) && N)
    {
        read(tom);
        read(jer);
        tom.x = tom.y = 1;
        jer.x = jer.y = N;
        bound(tom), bound(jer);
        RI(K);
        int s = max(tom.s, jer.s);
        FE(i, 1, K)
        {
            solve(i);
//            printf("tom: %d   %d\n", tom.x, tom.y);
//            printf("jerry %d  %d\n", jer.x, jer.y);
        }
        printf("%d %d\n", tom.x, tom.y);
        printf("%d %d\n", jer.x, jer.y);
    }
    return 0;
}


  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值