zoukankan      html  css  js  c++  java
  • HDOJ 4768 Flyer

    二分。。。。

    Flyer

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 722    Accepted Submission(s): 245


    Problem Description
    The new semester begins! Different kinds of student societies are all trying to advertise themselves, by giving flyers to the students for introducing the society. However, due to the fund shortage, the flyers of a society can only be distributed to a part of the students. There are too many, too many students in our university, labeled from 1 to 2^32. And there are totally N student societies, where the i-th society will deliver flyers to the students with label A_i, A_i+C_i,A_i+2*C_i,…A_i+k*C_i (A_i+k*C_i<=B_i, A_i+(k+1)*C_i>B_i). We call a student "unlucky" if he/she gets odd pieces of flyers. Unfortunately, not everyone is lucky. Yet, no worries; there is at most one student who is unlucky. Could you help us find out who the unfortunate dude (if any) is? So that we can comfort him by treating him to a big meal!
     

    Input
    There are multiple test cases. For each test case, the first line contains a number N (0 < N <= 20000) indicating the number of societies. Then for each of the following N lines, there are three non-negative integers A_i, B_i, C_i (smaller than 2^31, A_i <= B_i) as stated above. Your program should proceed to the end of the file.
     

    Output
    For each test case, if there is no unlucky student, print "DC Qiang is unhappy." (excluding the quotation mark), in a single line. Otherwise print two integers, i.e., the label of the unlucky student and the number of flyers he/she gets, in a single line.
     

    Sample Input
    2
    1 10 1
    2 10 1
    4
    5 20 7
    6 14 3
    5 9 1
    7 21 12
     

    Sample Output
    1 1
    8 1
     

    Source
     

    Recommend
    liuyiding
     



    #include <iostream>
    #include <cstdio>
    #include <cstring>

    using namespace std;
    const double INF=1e10;//不是这个怎么都过不了
    typedef long long int LL;

    int n;
    struct S
    {
        LL a,b,c;
    }s[21000];

    LL calu(LL x)
    {
        LL ans=0;
        for(int i=1;i<=n;i++)
        {
            x=min(x,s.b);
            if(x>=s.a)
            {
                ans+=(x-s.a)/s.c+1;
            }
        }
        return ans;
    }

    int main()
    {
        while(scanf("%d",&n)!=EOF)
        {
            for(int i=1;i<=n;i++)
            scanf("%lld %lld %lld",&s.a,&s.b,&s.c);

            LL Min=1,Max=INF,Mid;
            while(Min<Max)
            {
                Mid=(Min+Max)>>1;
                if(calu(Mid)%2) Max=Mid;
                else Min=Mid+1;
            }
            if(Min==INF)
                printf("DC Qiang is unhappy. ");
            else
            {
                printf("%d ",Min);
                cout<<calu(Min)-calu(Min-1)<<endl;
            }
        }
        return 0;
    }
    * This source code was highlighted by YcdoiT. ( style: Codeblocks )

  • 相关阅读:
    HDU-1160_FatMouse's Speed
    通过设置线程池的最小线程数来提高task的效率,SetMinThreads。
    使用publisher模式控制频繁的UI输出,避免Winform界面假死
    使用C# HttpWebRequest进行多线程网页提交。Async httpclient/HttpWebRequest实现批量任务的发布及异步提交和超时取消
    使用fiddlercore修改网页的返回内容
    培训班课程课时及费用管理系统V3.0,适合钢琴培训班、艺术培训班等
    关于新版税控数据库密码的获取
    WinForm 进度条
    C#对摄像头的操作示例,采用Aforge库
    用C# BigInteger实现的BigDecimal类,终于可以直接做四则运算了。
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350818.html
Copyright © 2011-2022 走看看