-
Notifications
You must be signed in to change notification settings - Fork 0
/
spin.java
67 lines (63 loc) · 1.54 KB
/
spin.java
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
56
57
58
59
60
61
62
63
64
65
66
67
/*
ID: 001207j1
LANG: JAVA
TASK: spin
*/
import java.io.*;
import java.util.Arrays;
public class spin {
public static void main(String[] args) throws Exception {
spin s = new spin();
s.run();
}
public static void run() throws Exception {
BufferedReader f = new BufferedReader(new FileReader("spin.in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("spin.out")));
int[][] rcd = new int[5][5];
int[] sp = new int[5];
int[][] ext = new int[5][5];
for (int i = 0; i < 5; i++) {
Arrays.fill(rcd[i], -1);
Arrays.fill(ext[i], -1);
}
for (int i = 0; i < 5; i++) {
String s[] = f.readLine().split(" ");
sp[i] = Integer.parseInt(s[0]);
for (int j = 0; j < Integer.parseInt(s[1]) * 2; j += 2) {
rcd[i][j / 2] = Integer.parseInt(s[j + 2]);
ext[i][j / 2] = Integer.parseInt(s[j + 3]);
}
}
int sec = 0;
while (true) {
boolean mark[] = new boolean[360];
boolean flag = true;
for (int i = 0; i < 5; i++) {
boolean flag2 = false;
boolean mark1[] = new boolean[360];
for (int j = 0; j < 5; j++) {
if (rcd[i][j] < 0)
continue;
for (int k = 0; k <= ext[i][j]; k++) {
int tmp = (rcd[i][j] + k) % 360;
if (i == 0 || mark[tmp])
flag2 = mark1[tmp] = true;
}
}
flag = flag && flag2;
mark = mark1;
for (int k = 0; k < 5; k++)
rcd[i][k] = (rcd[i][k] + sp[i]) % 360;
}
sec++;
if (sec > 360 || flag)
break;
}
if (sec < 360)
out.println(sec - 1);
else
out.println("none");
f.close();
out.close();
}
}