HDU 2932 extraordinarily tired students (strong brute force + modulo)

Source: Internet
Author: User

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)

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.