Hdu 4452 Running Rabbits 大模拟

题意:两只兔子在n*n的格子里移动,一只从左上角[1,1]开始,另一只从右下角[n,n]开始,然后经过一系列的条件:

1.他们可以它们可以沿东南西北4个方向走,但不可出格,各有各的速度,相遇时,两只兔子交换移动方向,碰边界时反向,各自还有自己的转左周期,周期一到即转左(但此时两只兔子相遇就不执行此周期转左),问K小时后两只兔子的坐标。

代码:

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <set>
const long long INF=(1ll<<60);
using namespace std;
struct node
{
    char flag;
    int x,y;
};
int main()
{
    int n;
    node First,Second;
    int fs,ft;
    int ss,st;
    while(scanf("%d",&n)&&n)
    {
        getchar();
        scanf("%c %d %d",&First.flag,&fs,&ft);
        getchar();
        scanf("%c %d %d",&Second.flag,&ss,&st);
        First.x=1;
        First.y=1;
        Second.x=n;
        Second.y=n;
        int k;
        scanf("%d",&k);
        for(int i=1; i<=k; i++)
        {
            if(First.flag=='N')
            {
                First.x-=fs;
                if(First.x <= 0)
                {
                    First.x +=fs;
                    First.x=fs-(First.x-1)+1;
                    First.flag='S';
                }
            }
            else if(First.flag=='S')
            {
                First.x+=fs;
                if(First.x > n)
                {
                    First.x-=fs;
                    First.x=n-(fs-(n-First.x));
                    First.flag='N';
                }
            }
            else if(First.flag=='W')
            {
                First.y-=fs;
                if(First.y <= 0)
                {
                    First.y +=fs;
                    First.y=fs-(First.y-1)+1;
                    First.flag='E';
                }
            }
            else if(First.flag=='E')
            {
                First.y+=fs;
                if(First.y > n)
                {
                    First.y-=fs;
                    First.y = n-(fs-(n-First.y));
                    First.flag='W';
                }
            }
            if(Second.flag=='N')
            {
                Second.x-=ss;
                if(Second.x <= 0)
                {
                    Second.x +=ss;
                    Second.x=ss-(Second.x-1)+1;
                    Second.flag='S';
                }
            }
            else if(Second.flag=='S')
            {
                Second.x+=ss;
                if(Second.x > n)
                {
                    Second.x-=ss;
                    Second.x=n-(ss-(n-Second.x));
                    Second.flag='N';
                }
            }
            else if(Second.flag=='W')
            {
                Second.y-=ss;
                if(Second.y <= 0)
                {
                    Second.y +=ss;
                    Second.y=ss-(Second.y-1)+1;
                    Second.flag='E';
                }
            }
            else if( Second.flag=='E')
            {
                 Second.y+=ss;
                if( Second.y > n)
                {
                     Second.y-=ss;
                     Second.y = n-(ss-(n- Second.y));
                     Second.flag='W';
                }
            }
            if(First.x ==  Second.x&&First.y ==  Second.y)
            {
                swap(First.flag,Second.flag);
            }
            else
            {
                if(i%ft==0)
                {
                    switch(First.flag)
                    {
                    case 'N':
                        First.flag='W';
                        break;
                    case 'S':
                        First.flag='E';
                        break;
                    case 'E':
                         First.flag='N';
                        break;
                    case 'W':
                         First.flag='S';
                        break;
                    }
                }
                if(i%st==0)
                {
                    switch(Second.flag)
                    {
                    case 'N':
                        Second.flag='W';
                        break;
                    case 'S':
                        Second.flag='E';
                        break;
                    case 'E':
                       Second.flag='N';
                        break;
                    case 'W':
                        Second.flag='S';
                        break;
                    }
                }
            }
        }
        printf("%d %d\n",First.x,First.y);
        printf("%d %d\n",Second.x,Second.y);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值