题意:模拟大富翁游戏,给出骰子会掷出的点数,问最后谁会赢。

题解:模拟。

View Code
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int ran[1005],id,top;
 6 int getnext()
 7 {
 8     return ran[id++];
 9 }
10 int pos[10],to[105],flag[105];
11 bool res[105];
12 int main()
13 {
14     int x,y;
15     top=0;
16     while(scanf("%d",&x),ran[top]=x)
17         top++;
18     int n;
19     while(scanf("%d",&n),n)
20     {
21         id=0;
22         memset(to,0,sizeof(to));
23         memset(flag,0,sizeof(flag));
24         memset(pos,0,sizeof(pos));
25         memset(res,false,sizeof(res));
26         while(scanf("%d%d",&x,&y),(x||y))
27             to[x]=y;
28         while(scanf("%d",&x),x)
29             if(x<0)
30                 flag[-x]=-1;
31             else
32                 flag[x]=1;
33         int p=0,d;
34         while(1)
35         {
36             p++;
37             if(p==n+1)
38                 p=1;
39             if(res[p])
40             {
41                 res[p]=false;
42                 continue;
43             }
44             d=getnext();
45             int t=pos[p]+d;
46             if(t>100)
47                 continue;
48             if(to[t])
49                 pos[p]=t=to[t];
50             else
51                 pos[p]=t;
52             if(t==100)
53             {
54                 printf("%d\n",p);
55                 break;
56             }
57             if(flag[t]<0)
58                 res[p]=true;
59             else if(flag[t]>0)
60                 p--;
61         }
62     }
63     return 0;
64 }