You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
|
|
|
|
|
#define N 1000000
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
int n;
|
|
|
|
|
int a[15], b[15], c[15];
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
int rnd = 0;
|
|
|
|
|
//n:学生的个数
|
|
|
|
|
while (scanf("%d", &n), n) {
|
|
|
|
|
//输入每个学生的Ai=清醒、Bi=睡觉,Ci=周期内的第Ci分钟
|
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
|
scanf("%d%d%d", &a[i], &b[i], &c[i]);
|
|
|
|
|
int t, count;//count代表清醒的人数
|
|
|
|
|
//开始一分钟一分钟的模拟
|
|
|
|
|
for (t = 1; t < N; t++) {
|
|
|
|
|
count = 0; //代表清醒的人数,每轮清零
|
|
|
|
|
//遍历每一个人
|
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
|
if (c[i] <= a[i])// c[i]代表周期内的第c[i]分钟
|
|
|
|
|
count++; //清醒中~
|
|
|
|
|
if (count == n) break; //如果全都清醒,那么就达到了目标
|
|
|
|
|
//正题,遍历每一组数据
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
//当到达周期末尾或到达即将睡觉的时候却发现清醒人数不少于睡觉人数时,重新开始计时
|
|
|
|
|
if (c[i] == a[i] + b[i] || (c[i] == a[i] && count >= n - count))
|
|
|
|
|
c[i] = 0; //重新计时,这个妙~
|
|
|
|
|
// 判断完这一分钟,需要记录上,结合上面的清零动作,就可以记录这一时间,是此同学的本周期内第几分钟。
|
|
|
|
|
c[i]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//到达很大的数了,还没有找到,那么只能是输出-1了
|
|
|
|
|
if (t == N) t = -1;
|
|
|
|
|
printf("Case %d: %d\n", ++rnd, t);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|