• 模拟 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 }
    编译人生,运行世界!
  • 相关阅读:
    进程间多线程同步三种方法
    C++ 生成随机数 srand()和rand()
    事件对象用于多线程之间的同步
    $.ajax()方法参数详解
    面向对象的属性
    对多选框进行操作,输出选中的多选框的个数
    jQuery如何检查某个元素在网页上是否存在
    关于$.fn
    c#基础班笔记
    Sublime Text 3的快捷键
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4655767.html
Copyright © 2020-2023  润新知