模拟 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 {
14     char c;
15     int d, s, t;
16     int x, y;
17 }r[3];
18
19 int main(void)        //HDOJ 4552 Running Rabbits
20 {
21 //    freopen ("K.in", "r", stdin);
22
23     int n;
24     while (scanf ("%d", &n) == 1)
25     {
26         if (n == 0)    break;
27         getchar ();
28         for (int i=1; i<=2; ++i)
29         {
30             scanf ("%c %d %d", &r[i].c, &r[i].s, &r[i].t);
31             if (r[i].c == ‘E‘)    r[i].d = 0;
32             else if (r[i].c == ‘N‘)    r[i].d = 1;
33             else if (r[i].c == ‘W‘)    r[i].d = 2;
34             else    r[i].d = 3;
35             getchar ();
36         }
37         int k;    scanf ("%d", &k);
38         r[1].x = r[1].y = 1;    r[2].x = r[2].y = n;
39
40         for (int i=1; i<=k; ++i)
41         {
42             for (int j=1; j<=2; ++j)
43             {
44                 if (r[j].d == 0)
45                 {
46                     if (r[j].y + r[j].s > n)
47                     {
48                         r[j].y = 2 * n - (r[j].y + r[j].s);
49                         r[j].d = 2;
50                     }
51                     else    r[j].y += r[j].s;
52                 }
53                 else if (r[j].d == 1)
54                 {
55                     if (r[j].x - r[j].s < 1)
56                     {
57                         r[j].x = 2 + r[j].s - r[j].x;
58                         r[j].d = 3;
59                     }
60                     else    r[j].x -= r[j].s;
61                 }
62                 else if (r[j].d == 2)
63                 {
64                     if (r[j].y - r[j].s < 1)
65                     {
66                         r[j].y = 2 + r[j].s - r[j].y;
67                         r[j].d = 0;
68                     }
69                     else    r[j].y -= r[j].s;
70                 }
71                 else if (r[j].d == 3)
72                 {
73                     if (r[j].x + r[j].s > n)
74                     {
75                         r[j].x = 2 * n - (r[j].x + r[j].s);
76                         r[j].d = 1;
77                     }
78                     else    r[j].x += r[j].s;
79                 }
80             }
81
82             if (r[1].x == r[2].x && r[1].y == r[2].y)    swap (r[1].d, r[2].d);
83             else
84             {
85                 if (i % r[1].t == 0)    r[1].d = (r[1].d + 1) % 4;
86                 if (i % r[2].t == 0)    r[2].d = (r[2].d + 1) % 4;
87             }
88         }
89
90         for (int i=1; i<=2; ++i)    printf ("%d %d\n", r[i].x, r[i].y);
91     }
92
93     return 0;
94 }
时间: 2024-08-07 22:41:59

模拟 HDOJ 4552 Running Rabbits的相关文章

[模拟] 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&qu

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

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

LPS HDOJ 4745 Two Rabbits

题目传送门 1 /* 2 题意:一只兔子顺时针跳,另一只逆时针跳,跳石头权值相等而且不能越过起点 3 LPS:这道就是LPS的应用,把环倍增成链,套一下LPS,然而并不能理解dp[i][i+n-2] + 1,看别人的解题报告吧,以后来补(玩游戏) 4 详细解释 5 */ 6 /************************************************ 7 * Author :Running_Time 8 * Created Time :2015-8-8 16:57:23 9

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

模拟 HDOJ 5387 Clock

题目传送门 1 /* 2 模拟:这题没啥好说的,把指针转成角度处理就行了,有两个注意点:结果化简且在0~180内:小时13点以后和1以后是一样的(24小时) 3 模拟题伤不起!计算公式在代码内(格式:hh/120, mm/120, ss/120) 4 */ 5 /************************************************ 6 * Author :Running_Time 7 * Created Time :2015-8-13 13:04:31 8 * Fil

模拟 HDOJ 5095 Linearization of the kernel functions in SVM

题目传送门 1 /* 2 题意:表达式转换 3 模拟:题目不难,也好理解题意,就是有坑!具体的看测试样例... 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <iostream> 8 #include <cstring> 9 #include <cmath> 10 #include <string> 11 #include <vector> 12 #i

模拟 HDOJ 5099 Comparison of Android versions

题目传送门 1 /* 2 题意:比较型号的大小 3 模拟:坑点在长度可能为5,此时设为'A' 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <iostream> 8 #include <cstring> 9 #include <cmath> 10 #include <string> 11 #include <vector> 12 #include &l

HDOJ 4745 Two Rabbits DP

Two Rabbits Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 944    Accepted Submission(s): 496 Problem Description Long long ago, there lived two rabbits Tom and Jerry in the forest. On a sunn