• 模拟 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
    ", r[i].x, r[i].y);
    91     }
    92 
    93     return 0;
    94 }
    编译人生,运行世界!
  • 相关阅读:
    自动轮播
    哈夫曼树的应用-金条划分
    计算两个日期相差的天数
    数据结构之算术表达式
    动态规划-矩阵最短路径
    动态规划-换钱最少货币数
    字母数字密码破解
    荷兰国旗问题
    集合并集
    进制数位幸运数
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4655767.html
Copyright © 2020-2023  润新知