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