USACO 3.2 Spinning Wheels

简单模拟

TASK: spin
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.000 secs, 3028 KB]
   Test 2: TEST OK [0.000 secs, 3028 KB]
   Test 3: TEST OK [0.000 secs, 3028 KB]
   Test 4: TEST OK [0.000 secs, 3028 KB]
   Test 5: TEST OK [0.000 secs, 3028 KB]
   Test 6: TEST OK [0.000 secs, 3028 KB]
   Test 7: TEST OK [0.000 secs, 3028 KB]
   Test 8: TEST OK [0.000 secs, 3028 KB]

All tests OK.

1 /*
2 PROG: spin
3 ID: jiafeim1
4 LANG: C++
5  */
6 #include <algorithm>
7 #include <iostream>
8 #include <fstream>
9 #include <string>
10 using namespace std;
11
12
13 int wheel_speed[8];
14 int wheel_lo[8][6][2];
15 int wx[8];
16 struct lo
17 {
18 int r[5];
19 lo(int r1,int r2,int r3,int r4,int r5)
20 {
21 r[0] = r1;
22 r[1] = r2;
23 r[2] = r3;
24 r[3] = r4;
25 r[4] = r5;
26 }
27 lo(){};
28 };
29 lo los[8];
30 int lo_top = 0;
31 int state[367];
32 int main()
33 {
34 std::ofstream fout("spin.out");
35 std::ifstream fin("spin.in");
36
37 for(int i = 0 ;i!=5;++i)
38 {
39 fin>>wheel_speed[i];
40 int w;
41 fin>>w;
42 wx[i] = w;
43 for(int j = 0;j!=w;++j)
44 fin>>wheel_lo[i][j][0]>>wheel_lo[i][j][1];
45 }
46
47 int count = 0;
48
49 do{
50 for(int i = 0;i!=360;++i) state[i] = 0;
51
52 for(int i = 0;i!=5;++i)
53 for(int j = 0;j!=wx[i];++j)
54 for(int q = wheel_lo[i][j][0];q<=wheel_lo[i][j][0]+wheel_lo[i][j][1];++q)
55 {
56 state[q%360]+=1;
57 }
58 for(int is = 0;is!=360;++is)
59 {
60 if(state[is]==5)
61 goto line;
62 }
63 for(int i = 0;i!=5;++i)
64 for(int j = 0;j!=wx[i];++j)
65 wheel_lo[i][j][0]= (wheel_lo[i][j][0]+wheel_speed[i])%360;
66
67 }while(++count < 360);
68 line:
69 if(count !=360)
70 fout<<count<<endl;
71 else
72 fout<<"none"<<endl;
73 fin.close();
74 fout.close();
75 return 0;
76 }
posted @ 2011-05-13 20:59  幻魇  阅读(262)  评论(0编辑  收藏  举报