HDU 2932 Extraordinarily Tired Students (暴力+取模还是很强大的)

题目链接:HDU 2932 Extraordinarily Tired Students

题意:给出N个学生的状态,(a,b,c)。a表示a分钟这醒着,b表示b分钟睡着,c表示刚开始是重周期(a+b)分钟的第c分钟开始。求第几分钟,所有的学生都没有睡觉。其中每个学生在睡觉前看一下是否睡觉的人数(包括他自己)比醒着的人数大,若是就睡觉,反之则不睡觉。

数据很小,暴力之,假设所有学生都没睡觉的时间不超过1000000,发现还可以更小。

AC代码;

#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;
}
时间: 2025-01-17 17:52:38

HDU 2932 Extraordinarily Tired Students (暴力+取模还是很强大的)的相关文章

HDU 2932 Extraordinarily Tired Students(数学 &amp; 模拟)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2932 Problem Description When a student is too tired, he can't help sleeping in class, even if his favorite teacher is right here in front of him. Imagine you have a class of extraordinarily tired studen

UVA - 12108 Extraordinarily Tired Students(模拟)

Extraordinarily Tired Students Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description When a student is too tired, he can't help sleeping in class, even if his favorite teacher is right here in front of hi

【模拟】UVa 12108 - Extraordinarily Tired Students

When a student is too tired, he can't help sleeping in class, even if his favorite teacher is right here in front of him. Imagine you have a class of extraordinarily tired students, how long do you have to wait, before all the students are listening

hdu 3221 Brute-force Algorithm(快速幂取模,矩阵快速幂求fib)

http://acm.hdu.edu.cn/showproblem.php?pid=3221 一晚上搞出来这么一道题..Mark. 给出这么一个程序,问funny函数调用了多少次. 我们定义数组为所求:f[1] = a,f[2] = b, f[3] = f[2]*f[3]......f[n] = f[n-1]*f[n-2].对应的值表示也可为a^1*b^0%p,a^0*b^1%p,a^1*b^1%p,.....a^fib[n-3]*b^fib[n-2]%p.即a,b的指数从n=3以后与fib数列

12108 - Extraordinarily Tired Students

When a student is too tired, he can't help sleeping in class, even if his favorite teacher is right here in front of him. Imagine you have a class of extraordinarily tired students, how long do you have to wait, before all the students are listening

HDU 1212 Big Number(C++ 大数取模)(java 大数类运用)

Big Number 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212 --每天在线,欢迎留言谈论. 题目大意: 给你两个数 n1,n2.其中n1 很大很大,n1%n2的值. 知识点: ①秦九韶公式:例:1314= ((1*10+3)*10+1)*10+4 ②(a*b)%c == (a%c)*(b%c) .(a+b)%c == (a%c)+(b%c) . 思路: 每步取模即可. C++ AC代码: 1 #include <iostream>

hdu 1452 Happy 2004 (快速幂+取模乘法逆元)

Problem Description Consider a positive integer X,and let S be the sum of all positive integer divisors of 2004^X. Your job is to determine S modulo 29 (the rest of the division of S by 29).Take X = 1 for an example. The positive integer divisors of

HDU 5832 A water problem(取模~)—— 2016中国大学生程序设计竞赛 - 网络选拔赛

传送门 A water problem Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 60    Accepted Submission(s): 37 Problem Description Two planets named Haha and Xixi in the universe and they were created wit

HDU - 3003 - Pupu (快速幂取模!)

Pupu Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1133    Accepted Submission(s): 445 Problem Description There is an island called PiLiPaLa.In the island there is a wild animal living in it