zoukankan      html  css  js  c++  java
  • Flyer(二分 HDU4768)

    Flyer
    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 2009 Accepted Submission(s): 736

    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
    2013 ACM/ICPC Asia Regional Changchun Online
    二分的思想

    #include <map>
    #include <set>
    #include <queue>
    #include <cstring>
    #include <string>
    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    typedef long long LL;
    
    struct node
    {
        int L;
        int R;
        int k;
    }a[20010];
    
    int n;
    
    LL Judge(LL s)
    {
        LL sum=0;
        for(int i=0;i<n;i++)
        {
            LL ans=a[i].R>s?s:a[i].R;
            if(ans>=a[i].L)
            {
                sum+=((ans-a[i].L)/a[i].k+1);
            }
        }
        return sum;
    }
    
    int main()
    {
        while(~scanf("%d",&n))
        {
            for(int i=0;i<n;i++)
            {
                scanf("%d %d %d",&a[i].L,&a[i].R,&a[i].k);
            }
            LL L=0,R=(1LL<<31);
            LL ans=-1;
            while(L<=R)
            {
                LL mid=(L+R)>>1;
                if(Judge(mid)%2)
                {
                    ans=mid;
                    R=mid-1;
                }
                else
                {
                    L=mid+1;
                }
            }
            if(ans==-1)
            {
                printf("DC Qiang is unhappy.
    ");
            }
            else
            {
                cout<<ans<<" "<<Judge(ans)-Judge(ans-1)<<endl;
            }
        }
        return 0;
    }
    
  • 相关阅读:
    php使用异或实现的加密解密
    js常用知识点总结
    linux删除、移动、拷贝时,加-f仍然会提示的解决办法
    CENTOS 挂载硬盘
    linux 常用压缩工具快速指南
    windows中path环境变量即时生效
    WDLINUX (Centos5.8) 安装 bcmath
    hyper中安装wdOS-1.0-x86_64(wdlinux)遇到的网卡问题
    WDLINUX (Centos5.8) 安装 soap
    算法书籍收藏
  • 原文地址:https://www.cnblogs.com/juechen/p/5255919.html
Copyright © 2011-2022 走看看