-
Notifications
You must be signed in to change notification settings - Fork 5
/
UVA-12108.cpp
73 lines (69 loc) · 1.19 KB
/
UVA-12108.cpp
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
68
69
70
71
72
73
#include<stdio.h>
int initArr[10][3];
int arr[10][3];
int stu;
bool allAwaken() {
int i;
for(i = 0; i < stu; ++i) {
if(arr[i][2] > arr[i][0]) return false;
}
return true;
}
bool sameInit() {
int i, j;
for(i = 0; i < stu; ++i) {
for(j = 0; j < 3; ++j) {
if(arr[i][j] != initArr[i][j]) {
return false;
}
}
}
return true;
}
void trans() {
int weaken = 0, sleep = 0;
int i, j;
for(i = 0; i < stu; ++i) {
if(arr[i][2] > arr[i][0]) {
++sleep;
} else {
++weaken;
}
}
for(i = 0; i < stu; ++i) {
if(arr[i][2] == arr[i][0]) {
if(sleep > weaken) {
++arr[i][2];
} else {
arr[i][2] = 1;
}
} else if(arr[i][2] == arr[i][0] + arr[i][1]) {
arr[i][2] = 1;
} else {
arr[i][2]++;
}
}
}
int main() {
int i, j, k, n = 0, t;
while(scanf("%d", &stu) == 1 && stu != 0) {
for(i = 0; i < stu; ++i) {
scanf("%d%d%d", &initArr[i][0], &initArr[i][1], &initArr[i][2]);
arr[i][0] = initArr[i][0];
arr[i][1] = initArr[i][1];
arr[i][2] = initArr[i][2];
}
t = 0;
for(i = 1; 1; ++i) {
if(allAwaken()) {
break;
}
if(i != 1 && sameInit()) {
t = -1;
break;
}
trans();
}
printf("Case %d: %d\n", ++n, t == -1 ? -1 : i);
}
}