Files
python/RuMenJingDian/UVa/UVa12108.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

41 lines
1.6 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}