天天看點

USACO3.23Spinning Wheels

直接枚舉角度 資料比較水吧 

1 /*
 2     ID: shangca2
 3     LANG: C++
 4     TASK: spin
 5  */
 6 #include <iostream>
 7 #include<cstdio>
 8 #include<cstring>
 9 #include<stdlib.h>
10 #include<algorithm>
11 using namespace std;
12 struct node
13 {
14     int l[10],r[10],k,v;
15 }p[10];
16 int f[6][370];
17 int main()
18 {
19     freopen("spin.in","r",stdin);
20     freopen("spin.out","w",stdout);
21     int i,j,o,g;
22     for(i = 1; i <= 5 ; i++)
23     {
24         cin>>p[i].v;
25         cin>>p[i].k;
26         for(j = 1; j <= p[i].k ; j++)
27         {
28             cin>>p[i].l[j]>>p[i].r[j];
29             if(p[i].l[j]+p[i].r[j]>=360)
30             {
31                 for(g = p[i].l[j]; g < 359 ; g++)
32                 f[i][g] = 1;
33                 for(g = 0; g <= (p[i].l[j]+p[i].r[j])%360 ; g++)
34                 f[i][g] = 1;
35             }
36             else
37             for(g = p[i].l[j] ; g <= p[i].l[j]+p[i].r[j] ; g++)
38                 f[i][g] = 1;
39         }
40     }
41     o = 0;
42     for(i = 0 ; i < 360 ; i++)
43     {
44         if(f[1][i]&&f[2][i]&&f[3][i]&&f[4][i]&&f[5][i])
45         {
46             printf("0
");
47             return 0;
48         }
49     }
50     while(1)
51     {
52         o++;
53         memset(f,0,sizeof(f));
54         for(i = 1; i <= 5 ; i++)
55         {
56             for(j = 1; j <= p[i].k ; j++)
57             {
58                 p[i].l[j] = (p[i].l[j]+p[i].v)%360;
59                 if(p[i].l[j]+p[i].r[j]>=360)
60                 {
61                     for(g = p[i].l[j]; g < 359 ; g++)
62                     f[i][g] = 1;
63                     for(g = 0; g <= (p[i].l[j]+p[i].r[j])%360 ; g++)
64                     f[i][g] = 1;
65                 }
66                 else
67                 for(g = p[i].l[j] ; g <= p[i].l[j]+p[i].r[j] ; g++)
68                 f[i][g] = 1;
69             }
70         }
71         for(i = 0 ; i < 360 ; i++)
72         {
73             if(f[1][i]&&f[2][i]&&f[3][i]&&f[4][i]&&f[5][i])
74             {
75                 printf("%d
",o);
76                 return 0;
77             }
78         }
79         if(o==10000)
80         {
81             puts("none");
82             return 0;
83         }
84     }
85     return 0;
86 }      

View Code