Running Rabbits

 1 #include <iostream>
 2 #include <string.h>
 3 #include <string>
 4 #include <fstream>
 5 #include <algorithm>
 6 #include <stdio.h>
 7 #include <vector>
 8 #include <queue>
 9 #include <set>
10 #include <cmath>
11 using namespace std;
12 const double eps = 1e-8;
13 const double pi=acos(-1.0);
14 const int INF=0x7fffffff;
15 unsigned long long uINF = ~0LL;
16 #define MAXN 100007
17 #define mod 1000000007
18 typedef long long LL;
19 int n,k;
20 struct node
21 {
22     int x,y;
23     char dir;
24     int spd;
25     int tru;
26 }t,j;
27 void move(node &p)
28 {
29     p.spd%=(n-1)*2;
30     switch(p.dir)
31     {
32         case 'W':
33         if(p.y-p.spd<1){p.dir='E';p.y=p.spd-(p.y-1)+1;}
34         else p.y-=p.spd;
35         break;
36         case 'E':
37         if(p.y+p.spd>n){p.dir='W';p.y=2*n-p.spd-p.y;}
38         else p.y+=p.spd;
39         break;
40         case 'N':
41         if(p.x-p.spd<1){p.dir='S';p.x=p.spd-(p.x-1)+1;}
42         else p.x-=p.spd;
43         break;
44         case 'S':
45         if(p.x+p.spd>n){p.dir='N';p.x=2*n-p.spd-p.x;}
46         else p.x+=p.spd;
47         break;
48     }
49 }
50 void turn(node &p)
51 {
52     switch(p.dir)
53     {
54         case 'W':p.dir='S';break;
55         case 'E':p.dir='N';break;
56         case 'S':p.dir='E';break;
57         case 'N':p.dir='W';break;
58     }
59 }
60 int main()
61 {
62     //freopen("0.in","r",stdin);
63     //freopen("01.in","w",stdout);
64     while(scanf("%d",&n),n!=0)
65     {
66         getchar();scanf("%c%d%d",&t.dir,&t.spd,&t.tru);
67         getchar();scanf("%c%d%d",&j.dir,&j.spd,&j.tru);
68         scanf("%d",&k);
69         t.x=t.y=1;j.x=j.y=n;
70         for(int i=1;i<=k;i++)
71         {
72             move(t);move(j);
73             if(t.x==j.x&&t.y==j.y)
74             {
75                 char temp=t.dir;
76                 t.dir=j.dir;
77                 j.dir=temp;
78             }
79             else
80             {
81                 if(i%t.tru==0)turn(t);
82                 if(i%j.tru==0)turn(j);
83             }
84         //printf("%c %d %d
",t.dir,t.x,t.y);
85         //printf("%c %d %d
",j.dir,j.x,j.y);
86         //printf("
");
87         }
88         printf("%d %d
",t.x,t.y);
89         printf("%d %d
",j.x,j.y);
90     }
91     return 0;
92 }

模拟 昨天一天死在麻将上~

原文地址:https://www.cnblogs.com/TO-Asia/p/3234307.html