hdu 4768 Flyer (二分)

Flyer

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


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


思路:
突破口肯定是只有一个人是奇数,那么二分区间就够了。

ps:
吐槽一下,异或的暴力代码数据强一点是肯定TLE的,数据水了,没办法。

感想:
二分的思路比赛时自己没想到,lcm想到的,哎,比赛时思维为什么就那么烂了,比赛时还不能冷静下来推那个计算一个区间有多少个满足数列个数的公式了,好忧伤。不存在时输出时忘记加'.'了,我晕,找错找半天,我要抓狂了。

代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
//#pragma comment (linker,"/STACK:102400000,102400000")
#define maxn 20005
#define mod 1000000000
#define INF 0x3f3f3f3f
using namespace std;

typedef __int64 ll;
ll n,m,ans,flag;
ll id,cnt,mi,ma;
struct Node
{
    ll a,b,c;
} pp[maxn];

ll calnum(ll le,ll ri)
{
    ll i,j,t,tl,tr,sum=0;
    for(j=1; j<=n; j++)
    {
        tl=max(pp[j].a,le);
        tr=min(pp[j].b,ri);
        if(tl>tr||tr<pp[j].a||tl>pp[j].b) continue ;
        sum=sum+(tr-(pp[j].a-pp[j].c))/pp[j].c-max(0LL,(tl-1-(pp[j].a-pp[j].c))/pp[j].c);
    }
    return sum;
}
void solve()
{
    ll i,j,le,mid,ri,t;
    le=mi;
    ri=ma;
    while(le<ri)
    {
        mid=(le+ri)>>1;
        t=calnum(le,mid);
        if(t&1LL) ri=mid;
        else le=mid+1;
    }
    id=le;
    cnt=calnum(le,le);
}
int main()
{
    int i,j,t,test;
    while(~scanf("%I64d",&n))
    {
        mi=1000000000000LL;
        ma=0;
        for(i=1; i<=n; i++)
        {
            scanf("%I64d%I64d%I64d",&pp[i].a,&pp[i].b,&pp[i].c);
            mi=min(pp[i].a,mi);
            ma=max(ma,pp[i].b);
        }
        if(!(calnum(mi,ma)&1)) printf("DC Qiang is unhappy.\n");
        else
        {
            solve();
            printf("%I64d %I64d\n",id,cnt);
        }
    }
    return 0;
}







 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值