#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int student[200][200]={0};
int main()
{
int n,kase = 0;
while(~scanf("%d", &n)&&n)
{
int sum = 0;
for(int i = 0; i < n; i++)
{
scanf("%d %d %d",&student[i][1],&student[i][2], &student[i][3]);
if(student[i][3] > student[i][1])
{
student[i][0] = 1;
sum++;
}
else
{
student[i][0] = 0;
}
if(student[i][0])
student[i][4] = student[i][3] - student[i][1]-2;
else
student[i][4] = student[i][3]-2;
}
printf("Case %d: ",++kase);
int i;
for(i = 1;i<=2000;i++)
{
for(int j = 0;j < n; j++)
{
student[j][4]++;
if(student[j][0])
{
if(student[j][4]==student[j][2])
{
student[j][0] = 0;
student[j][4] = 0;
}
}
else
{
if(student[j][4]==student[j][1])
{
if(n-sum < sum)
{
student[j][0] = 1;
student[j][4] = 0;
}
else
{
student[j][4] = 0;
}
}
}
}
sum = 0;
for(int j = 0; j < n; j++)
{
if(student[j][0])
{
sum++;
}
}
if(!sum)
{
printf("%d\n",i);
break;
}
}
if(i>2000)
printf("-1\n");
}
return 0;
}
UVA-12108
最新推荐文章于 2022-02-02 23:05:39 发布