二分。。。。

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.\n");
        else
        {
            printf("%d ",Min);
            cout<<calu(Min)-calu(Min-1)<<endl;
        }
    }
    return 0;
}

* This source code was highlighted by YcdoiT. ( style: Codeblocks )

HDOJ 4768 Flyer的更多相关文章

  1. HDU 4768 Flyer(二分)

    题目链接: 传送门 Flyer Time Limit: 1000MS     Memory Limit: 32768 K Description The new semester begins! Di ...

  2. HDU 4768 Flyer(二分法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4768 题目大意:每组数据有n行输入,每行有三个数A.B.C,A<=B且小于2^32,从A到B每隔 ...

  3. 2013长春网赛1010 hdu 4768 Flyer

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4768 题意:有n个社团发传单,每个社团发给编号为A_i, A_i+C_i,A_i+2*C_i,…A_i ...

  4. HDU 4768 Flyer (2013长春网络赛1010题,二分)

    Flyer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  5. hdu 4768 Flyer 二分

    思路:由于最多只有一个是奇数,所以二分枚举这个点,每次判断这个点的左边区间段所有点的和作为 二分的依据. 代码如下: #include<iostream> #include<cstd ...

  6. HDU 4768 Flyer【二分】||【异或】

    <题目链接> <转载于  >>> > 题目链接: n个社团派发传单,有a,b,c三个参数,派发的规则是,派发给序号为a,a+c....a+k*c,序号要求是小 ...

  7. HDU 4768: Flyer

    题意: 有N个社团,每个社团三个属性A,B,C,表示会向编号A+k*C的同学发传单(k=0,1,2...  && A+k*C <= B).题目保证最多有一个人收到的传单数是奇数. ...

  8. hdu 4768 Flyer (异或操作的应用)

    2013年长春网络赛1010题 继巴斯博弈(30分钟)签到后,有一道必过题(一眼即有思路). 思路老早就有(40分钟):倒是直到3小时后才被A掉.期间各种换代码姿态! 共享思路: unlucky st ...

  9. hdu 4678

    HDU 4768: Flyer 题意: 有N个社团,每个社团三个属性A,B,C,表示会向编号A+k*C的同学发传单(k=0,1,2...  && A+k*C <= B).题目保证 ...

随机推荐

  1. C++ 动态数组实例

    一维动态数组的实例: #include <iostream> using namespace std; int main() { int *arr; int n; cout<< ...

  2. K米交流会现场图

  3. JavaScript函数之美~

    JavaScript函数之美~ 这篇文章,我将就以下几个方面来认识JavaScript中的函数. 函数为什么是对象,如何定义函数? 如何理解函数可以作为值被传递 函数的内部对象.方法以及属性 第一部分 ...

  4. Ps 技巧

    一.动作(批处理) 二.让图片更清晰 三.标尺 四.画面还原 五.内容识别比例(改变身材) 六.移花接木 七.多人头像 八.多重曝光 九.突出肌肉线条或者脸部轮廓 十.给照片换一个天空 十一.制作光束 ...

  5. openssl生成https证书 (转)

    1.首先要生成服务器端的私钥(key文件):openssl genrsa -des3 -out server.key 1024运行时会提示输入密码,此密码用于加密key文件去除key文件口令的命令:o ...

  6. iterator and iterable

    前者是迭代器 后者是接口,List等继承这个接口

  7. php比较时间戳与时间差计算函数( 实用)

    PHP时间比较和时间差如何计算 <?php $zero1=date(“y-m-d h:i:s”); $zero2=”-- ::′; echo “zero1的时间为:”.$zero1.”<b ...

  8. 蛋疼的vs

    这个vs2008 难用的很,要是叫我选肯定vs高版本的,vs2012或者直接vs2015

  9. 20145212 《Java程序设计》第5周学习总结

    20145212 <Java程序设计>第5周学习总结 教材学习内容总结 第八章 1.Java中所有错误都会被打包为对象,通过try和catch语法可以对代表错误的对象做处理. try{ . ...

  10. ubuntu下安装wine1.8和阿里旺旺

    参考:http://www.linuxidc.com/Linux/2015-12/126722.htm和http://www.linuxidc.com/Linux/2016-05/131131.htm ...