二分。。。。

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. python统计nginx脚本信息

    #!/usr/bin/env python # -*- coding: utf-8 -*- import urllib2 import json import subprocess import th ...

  2. Swift 吐槽下Swift里一个逼死强迫症的语法:中缀语法

    中缀语法是OC里特有的一种,就是在函数的参数前面加一个解释词,让调用的时候明白该参数的含义 比如: -(void)processDataWithparamaA:(NSString *)paramaA ...

  3. jQuery知识点总结(第六天)

    今天工作繁忙,晚上又和所谓的'朋友',吃了自助烧烤. 但我内心是很抗拒的,不知为了什么,竟然稀奇古怪的答应了下来,竟要去吃饭.我向来不喜欢去凑热闹,特别是和志趣不投的人在一起吃,对方所说的话,自己根本 ...

  4. 通过rsync搭建一个远程备份系统(二)

    Rsync+inotify实时备份数据 rsync在同步数据的时候,需要扫描所有文件后进行对比,然后进行差量传输,如果文件达到了百万或者千万级别以上是,扫描文件的时间也很长,而如果只有少量的文件变更了 ...

  5. html代码规范

    HTML代码规范   我们知道,前端工程师入门容易,通过学习基本的HTML和CSS就能在浏览器上看到实际的效果,可是要写好的HTML,就不是那么容易了.这里将和大家分享HTML规范,希望大家读完之后都 ...

  6. JS-计算器制作

    不完善,接下来想着把运算符分开成一个一个的按钮... <!DOCTYPE html><html> <head> <meta charset="UTF ...

  7. HTML CSS + DIV实现整体布局

    HTML CSS + DIV实现整体布局 1.技术目标: 开发符合W3C标准的Web页面 理解盒子模型 实现DIV+CSS整体布局 2.什么是W3C标准? W3C:World Wide Web Con ...

  8. c中三大区的解析

    1.栈,堆和静态存储区是 堆和静态存储区是C语言程序常涉及的三个基本内语言程序常涉及的三个基本内存区2.栈区主要用于函数调用的使用3.堆区主要是用于内存的动态申请和归还4.静态存储区用于保存全局变量和 ...

  9. 一个C#解决方案中各文件夹存放了些什么

    在VS2015中"生成"(Build)的过程: Source Code(.cs) -> Compile -> Object File(intermediate file ...

  10. JavaScript 、jQuery动态创建元素的关键字~

    JavaScript动态创建元素: 1.创建元素  如:a 标签 var alink= document.createElement("a"); 2.j添加元素属性 alink.h ...