Link: HDU 2932 extraordinarily tired students
Question: Give the status of N students (A, B, C ). A indicates that a minute is awake, B indicates that B minutes are asleep, and C indicates that the beginning is the c minute of the recurrence (a + B) Minute. Wait a few minutes until all the students go to bed. Before going to bed, each student needs to check whether the number of Students Sleeping (including himself) is larger than the number of awake students. If they do, they will not go to bed.
The data is small and violent. If all the students do not go to bed for less than 1000000 times, the data can be smaller.
AC code;
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;const int maxn=20;int a[maxn],b[maxn],c[maxn];int main(){ int i,j; int n,T,cas=1; while(scanf("%d",&n)!=EOF,n) { for(i=0; i<n; i++) scanf("%d %d %d",&a[i],&b[i],&c[i]); for(i=0; i<100000; i++) { int cont=0; for(j=0; j<n; j++) { T=a[j]+b[j]; if((i+c[j]-1)%T<a[j]) cont++;//醒; else cont--; } if(cont>0) break; } printf("Case %d: ",cas++); if(i>=100000) printf("-1\n"); else { int ans=-1; for(j=0; j<n; j++) { T=a[j]+b[j]; if((i+c[j]-1)%T>=a[j])//醒; ans=max(ans,T-(i+c[j]-1)%T); } printf("%d\n",i+ans+1); } } return 0;}
HDU 2932 extraordinarily tired students (strong brute force + modulo)