加载中…
个人资料
C_down
C_down
  • 博客等级:
  • 博客积分:0
  • 博客访问:74,749
  • 关注人气:27
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
相关博文
推荐博文
谁看过这篇博文
加载中…
正文 字体大小:

hdu 4452(模拟题)

(2012-10-30 11:17:03)
标签:

杂谈

分类: ACM比赛/cf

题目说的有些不太清楚。

弄懂了题意就是简单地模拟了。。。

 

有几点要注意的:

1. 一开始是算 0 小时,所以不转向

2. 如果两只兔子相遇 , 并且一只兔子要turn left,那么这只兔子只转向另一只兔子的方向,不turn left。

3. 注意每次进行转向操作都是在这一个小时的最开始时刻。 也就是先判断应该往那个方向转。再走

Running Rabbits

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 106 Accepted Submission(s): 75


Problem Description
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 4×4 field and some coordinates of its cells are shown below:
hdu <wbr>4452(模拟题)

The rabbits can run in four directions (north, south, west and east) and they run at certain speed measured by cells per hour. The rabbits can't get outside of the field. If a rabbit can't run ahead any more, it will turn around and keep running. For example, in a 5×5 grid, if a rabbit is heading west with a speed of 3 cells per hour, and it is in the (3, 2) cell now, then one hour later it will get to cell (3,3) and keep heading east. For example again, if a rabbit is in the (1,3) cell and it is heading north by speed 2,then a hour latter it will get to (3,3). The rabbits start running at 0 o'clock. If two rabbits meet in the same cell at k o'clock sharp( k can be any positive integer ), Tom will change his direction into Jerry's direction, and Jerry also will change his direction into Tom's original direction. This direction changing is before the judging of whether they should turn around.
The rabbits will turn left every certain hours. For example, if Tom turns left every 2 hours, then he will turn left at 2 o'clock , 4 o'clock, 6 o'clock..etc. But if a rabbit is just about to turn left when two rabbit meet, he will forget to turn this time. Given the initial speed and directions of the two rabbits, you should figure out where are they after some time.


 

Input
There are several test cases.
For each test case:
The first line is an integer N, meaning that the field is an N×N grid( 2≤N≤20).
The second line describes the situation of Tom. It is in format "c s t"。c is a letter indicating the initial running direction of Tom, and it can be 'W','E','N' or 'S' standing for west, east, north or south. s is Tom's speed( 1≤s
The third line is about Jerry and it's in the same format as the second line.
The last line is an integer K meaning that you should calculate the position of Tom and Jerry at K o'clock( 1 ≤ K ≤ 200).
The input ends with N = 0.


 

Output
For each test case, print Tom's position at K o'clock in a line, and then print Jerry's position in another line. The position is described by cell coordinate.


 

Sample Input
4 E 1 1 W 1 1 2 4 E 1 1 W 2 1 5 4 E 2 2 W 3 1 5 0


 

Sample Output
2 2 3 3 2 1 2 4 3 1 4 1


 

Source


 

Recommend
zhuyuanchen520
 
#include
#include
#include
#include
using namespace
std;
struct
node
{

    char
flag;
    int
x,y;
};


int
main()
{
   
    int
n;
    node tm,jy;
    int
ts,tt;
    int
js,jt;
    while
(scanf("%d",&n)&&n)
    {

        getchar();
        scanf("%c %d %d",&tm.flag,&ts,&tt);
        getchar();
        scanf("%c %d %d",&jy.flag,&js,&jt);
        tm.x=1; tm.y=1;
        jy.x=n; jy.y=n;
        int
cnt;
        scanf("%d",&cnt);
        for
(int i=1;i<=cnt;i++)
        {

            if
(tm.flag=='N')
            {

                tm.x-=ts;
                if
(tm.x <= 0)
                {

                    tm.x +=ts;
                    tm.x=ts-(tm.x-1)+1;
                    tm.flag='S';
                 }
            }

            else
            if
(tm.flag=='S')
            {

                tm.x+=ts;
                if
(tm.x > n)
                {

                    tm.x-=ts;
                    tm.x=n-(ts-(n-tm.x));
                    tm.flag='N';
                }
            }
else
            if
(tm.flag=='W')
            {

                tm.y-=ts;
                if
(tm.y <= 0)
                {

                    tm.y +=ts;
                    tm.y=ts-(tm.y-1)+1;
                    tm.flag='E';
                 }
            }
else
            if
(tm.flag=='E')
            {

                tm.y+=ts;
                if
(tm.y > n)
                {

                    tm.y-=ts;
                    tm.y = n-(ts-(n-tm.y));
                    tm.flag='W';
                }
            }

            //////////////////////
            if(jy.flag=='N')
            {

                jy.x-=js;
                if
(jy.x <= 0)
                {

                    jy.x +=js;
                    jy.x=js-(jy.x-1)+1;
                    jy.flag='S';
                 }
            }
else
            if
(jy.flag=='S')
            {

                jy.x+=js;
                if
(jy.x > n)
                {

                    jy.x-=js;
                    jy.x=n-(js-(n-jy.x));
                    jy.flag='N';
                }
            }
else
            if
(jy.flag=='W')
            {

                jy.y-=js;
                if
(jy.y <= 0)
                {

                    jy.y +=js;
                    jy.y=js-(jy.y-1)+1;
                    jy.flag='E';
                 }
            }
else
            if
(jy.flag=='E')
            {

                jy.y+=js;
                if
(jy.y > n)
                {

                    jy.y-=js;
                    jy.y = n-(js-(n-jy.y));
                    jy.flag='W';
                }
            }

            //////////////////////
            if(tm.x == jy.x&&tm.y == jy.y)
            {

                swap(tm.flag,jy.flag);
            }

            else

            {

                if
(i%tt==0)
                {

                    switch
(tm.flag)
                    {

                    case
'N': tm.flag='W'; break;
                    case
'S': tm.flag='E'; break;
                    case
'E': tm.flag='N'; break;
                    case
'W': tm.flag='S'; break;
                    }
                }

                if
(i%jt==0)
                {

                    switch
(jy.flag)
                    {

                    case
'N': jy.flag='W'; break;
                    case
'S': jy.flag='E'; break;
                    case
'E': jy.flag='N'; break;
                    case
'W': jy.flag='S'; break;
                    }
                }
            }
        }

        printf("%d %d\n",tm.x,tm.y);
        printf("%d %d\n",jy.x,jy.y);
    }

    return
0;
}

0

阅读 评论 收藏 转载 喜欢 打印举报/Report
  • 评论加载中,请稍候...
发评论

    发评论

    以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

      

    新浪BLOG意见反馈留言板 电话:4000520066 提示音后按1键(按当地市话标准计费) 欢迎批评指正

    新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

    新浪公司 版权所有