UVa 12108 particularly sleepy students

Source: Internet
Author: User

https://vjudge.net/problem/UVA-12108

Test instructions: Given the "Awake-sleep" cycle and the initial point of time for N students, each student needs to determine whether the number of people sleeping in the class is more stringent than the number of sober people during sleep, or else to judge after insisting on a sober cycle. Find out how long the whole class is awake.

Idea: Water problem bar. Over and over again, the condition of the loop termination is the same as the initial state.

1#include <iostream>2 using namespacestd;3 4 structNode5 {6     intA;7     intB;8     intC;9}stu[ A];Ten intans[ A]; One  A intMain () - { -Freopen ("D:\\txt.txt","R", stdin); the     intN,sleep,kase=0; -      while(Cin >> N &&N) -     { -Sleep =0; +          for(inti =0; I < n; i++) -         { +CIN >> Stu[i]. A >> Stu[i]. B >>Stu[i]. C; AAns[i] =Stu[i]. C; at             if(Stu[i]. C>stu[i]. A) sleep++;//count the initial number of people asleep -         } -         intCount =0; -          for(intk=1;; k++) -         { -  in             if(Sleep = =0) -             { tocout <<" Case"<< ++kase <<": "<< k <<Endl; +                  Break; -             } the  *             if(Count = =N) $             {Panax Notoginsengcout <<" Case"<< ++kase <<":-1"<<Endl; -                  Break; the             } +  ACount =0; the             intFlag =0; +  -              for(inti =0; I < n; i++) $             { $Ans[i] = ans[i]% (Stu[i]. A + stu[i]. B) +1; -                 if(Ans[i] = =1) flag--; -                 if(Ans[i] = = Stu[i]. A +1) the                 { -                     if(Sleep <= N-sleep)WuyiAns[i] =1; the                     Elseflag++; -                 } Wu                 if(Ans[i] = = Stu[i]. C) count++; -             } AboutSleep + =Flag; $         } -     } -     return 0; -}

UVa 12108 particularly sleepy students

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.