USACO Spinning Wheels

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
ID: wcr19961
PROG: spin
LANG: C++11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = 7;
const int maxm = 365;
int ok[maxm];
int v[maxn], num[maxn];
int p[maxn][maxn], w[maxn][maxn];
bool check(int x) {
memset(ok, 0, sizeof ok);
for (int i = 1; i <= 5; ++i) {
int px = x * v[i];
for (int j = 0; j < num[i]; ++j) {
for (int k = 0; k <= w[i][j]; ++k) {
if (ok[(px + p[i][j] + k) % 360] == i - 1) {
++ok[(px + p[i][j] + k) % 360];
}
}
}
}
for (int i = 0; i < 360; ++i) {
if (ok[i] == 5) {
return true;
}
}
return false;
}
int main() {
freopen("spin.in", "r", stdin);
freopen("spin.out", "w", stdout);
for (int i = 1; i <= 5; ++i) {
scanf("%d%d", &v[i], &num[i]);
for (int j = 0; j < num[i]; ++j) {
scanf("%d%d", &p[i][j], &w[i][j]);
}
}
for (int i = 0; i < 360; ++i) {
if (check(i)) {
printf("%d\n", i);
return 0;
}
}
puts("none");
return 0;
}