最近在填紫书上的坑(以前由于浮躁没有做的习题),发现还是有很多题比较麻烦,虽然思路很容易想,但就是写不出ac代码,可能这就是眼高手低吧。希望在接下来的学习生活中,从小事做起,向着自己的目标而努力吧。
这道题挺有意思,虽然水,但是有一些细节不注意很容易wa,甚至样例都过不了。
#include <stdio.h>
#define MAXN 520
typedef struct {
int a, b, c, period;
int awake;
} Stu;
Stu stu[15];
int main() {
//freopen("input.txt", "r", stdin);
int n;
int kase = 0;
while(scanf("%d", &n) != EOF && n) {
int awake;
for(int i = 0; i < n; i++) {
scanf("%d%d%d", &stu[i].a, &stu[i].b, &stu[i].c);
stu[i].period = stu[i].a + stu[i].b;
if (stu[i].a >= stu[i].c) {
stu[i].awake = 1;
}
else {
stu[i].awake = 0;
}
}
int flag = 1;
for(int t = 1; t < MAXN; t++) {
awake = 0;
for(int i = 0; i < n; i++)
if (stu[i].awake) awake++;
if (awake == n) {
printf("Case %d: %d\n", ++kase, t);
flag = 0;
break;
}
for(int i = 0; i < n; i++) {
if (stu[i].c == stu[i].a) {
if (n - awake <= awake) {
stu[i].c = 1;
}
else {
stu[i].c++;
stu[i].awake = 0;
}
}
else if (stu[i].c == stu[i].period) {
stu[i].awake = 1;
stu[i].c = 1;
}
else stu[i].c += 1;
}
}
if (flag) printf("Case %d: -1\n", ++kase);
}
return 0;
}