UVA12108-4.8(ti)-Extraordinarily Tired Students

UVA12108-4.8(ti)-Extraordinarily Tired Students
题目描述:
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=833&problem=3260&mosmsg=Submission+received+with+ID+18644727
课堂上有n个学生(你<=10)。每个学生都有一个‘’睡眠-清醒‘’周期,其中第i个学生醒Ai分钟后睡Bi分钟,然后重复周期,初始时第i个学生处在他的周期的第Ci分钟。每个学生在临睡前会查看全班睡觉人数是否 严格大于清醒人数,只有这个条件满足时才睡觉,否者就坚持听课Ai分钟后再次检查这个条件。问讲过多长时间后全班都清醒。
可能并不存在全部清醒的时刻,此时输出-1。
题目分析:
这个题意外的比较好做。(第四章做怕了,劝退系列==)
用一个二维数组存周期,一个一位数组存状态,然后用循环一遍一遍的找就可以了,到临界点时判断一下是否归零就好了。
==这里说可能并不存在全部清醒的时刻,我也没想出来什么好的判断条件,所以就把循环的停止条件弄的比较大,如果循环结束还没有找到,就当做没有好了==感觉这办法很不靠谱的样子=。=
给出代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    //freopen("D:\\output.txt","w",stdout);
   int num[12][2];
   int num1[12];
   int n;
   int mark=0;
   while(scanf("%d",&n)!=EOF)
   {
       if(n==0)
        break;
       mark++;
       int i,j;
       for(i=1;i<=n;i++)
       {
           for(j=1;j<=2;j++)
              {
                  scanf("%d",&num[i][j]);
              }
            scanf("%d",&num1[i]);
            num1[i]-=1;
       }
       int book=0;
       for(i=0;i<=1000;i++)
       {   //printf("%d\n",i);
           int sleep=0;
           int unsleep=0;
           for(j=1;j<=n;j++)
           {
               num1[j]++;
               if(num1[j]<=num[j][1])
                unsleep++;
               else
                sleep++;
               if(num1[j]==num[j][1]+num[j][2])
                num1[j]=0;
           }
           if(sleep==0)
           {
               book=1;
               break;
           }
           if(sleep<=unsleep)
           {
               for(j=1;j<=n;j++)
               {
                   if(num1[j]==num[j][1])
                    num1[j]=0;
               }
           }
       }
       printf("Case %d: ",mark);
       if(book)
        printf("%d\n",i+1);
       else
        printf("-1\n");
   }
   return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面有篇英文课文,请编程找出课文中所有的单词,统计单词出现的次数,统计时不区分字母的大小写,最后按出现的次数从大到小显示出现3次以上各个单词及次数。例如,结果显示如下: the 18 a 14 puma 9 in 8 it 8 ...(略) 英文课文如下: Pumas are large, cat-like animals which are found in America. When reports came into London Zoo that a wild puma had been spotted forty-five miles south of London, they were not taken seriously. However, as the evidence began to accumulate, experts from the Zoo felt obliged to investigate, for the descriptions given by people who claimed to have seen the puma were extraordinarily similar. The hunt for the puma began in a small village where a woman picking blackberries saw 'a large cat' only five yards away from her. It immediately ran away when she saw it, and experts confirmed that a puma will not attack a human being unless it is cornered. The search proved difficult, for the puma was often observed at one place in the morning and at another place twenty miles away in the evening. Wherever it went, it left behind it a trail of dead deer and small animals like rabbits. Paw prints were seen in a number of places and puma fur was found clinging to bushes. Several people complained of 'cat-like noises' at night and a businessman on a fishing trip saw the puma up a tree. The experts were now fully convinced that the animal was a puma, but where had it come from ? As no pumas had been reported missing from any zoo in the country, this one must have been in the possession of a private collector and somehow managed to escape. The hunt went on for several weeks, but the puma was not caught. It is disturbing to think that a dangerous wild animal is still at large in the quiet countryside.
最新发布
06-06

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值