HDU 4768Flyer(二分 自己思维太死了)

Flyer

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


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
 

Recommend
liuyiding
 

           题目大意:给你n个区间,每次给定的区间,a-b区间每隔c个人发一张传单。这里面最多有一个人得到的传单数是奇数,如果存在奇数,把这个数人编号找出来并输出他得到的传单数。如果不存在输出DC Qiang is unhappy.

 

       解题思路:虽然也经常会使用二分三分,但是看这个题目的时候,竟然没有丝毫的意思会向那方面去想,倒想统计每个人得到的传单数目,但又保存不下来。二分区间,如果1~mid存在奇数,那么r=mid,否则l=mid+1.具体实现见代码。

 

       题目地址:Flyer

 

AC代码:

#include
#include
#include
#include
using namespace std;
__int64 a[20005],b[20005],c[20005];
int n;

__int64 cal(__int64 x)
{
    int i;
    __int64 sum=0;
    for(i=0;i=a[i])
           sum+=(mi-a[i])/c[i]+1;
    }
    return sum;
}

int main()
{
    int i;
    while(~scanf("%d",&n))
    {
        for(i=0;i>1;
        while(l>1;
            //printf("%I64d %I64d %I64d\n",l,r,mid);
        }

        if(cal(mid)%2==0)
           puts("DC Qiang is unhappy.");
        else
           printf("%I64d %I64d\n",mid,cal(mid)-cal(mid-1));
    }
    return 0;
}

//46MS


 

 

你可能感兴趣的:(二分三分)