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.\n");
}
else
{
cout<<ans<<" "<<Judge(ans)-Judge(ans-1)<<endl;
}
}
return 0;
}

Flyer(二分 HDU4768)的更多相关文章

  1. HDU4768:Flyer [ 二分的奇妙应用 好题 ]

    传送门 Flyer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. hdu 4768 Flyer 二分

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

  3. HDU 4768 Flyer(二分)

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

  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【二分】||【异或】

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

  6. hdu4768二分答案

    /* 如果发的传单是偶数,那么所有人都收到双数张. 仅考虑发了单数张传单,二分答案x,如果x左边是偶数,那么答案在右侧,如果x左边是奇数,那么答案在左侧 */ #include<iostream ...

  7. [hdu4768]二分

    http://acm.hdu.edu.cn/showproblem.php?pid=4768 题意:n个传单分别发给编号为ai, ai + ci, ai + 2 * ci, .. , ai + k * ...

  8. hdu4768 非常规的二分

    题意:       n个社团给同学发传单,同学一共有1--2^31这么多,每个社团有三个数A ,B ,C ,只有 满足 A ,A + C ,A + C + C ...A + KC <= B 的学 ...

  9. HDOJ 4768 Flyer

    二分.... Flyer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

随机推荐

  1. 使用Font Awesome替换你的网站图标

    http://fortawesome.github.io/Font-Awesome/whats-new/ 使用Font Awesome替换你的网站图标 ******************IE7BUG ...

  2. Spring.Net 配置文件

    方法一. 直接在程序配置文件中配置 <configuration> <configSections> <sectionGroup name="spring&qu ...

  3. hadoop-1.2.1安装配置

    1.准备三台节点 hnd1  hnd2  hnd3 下载 hadoop 下载地址:http://apache.fayea.com/hadoop/common/ API文档:http://hadoop. ...

  4. java 中的2个接口 Comparable和Comparator

    像Integer.String这些类型的数据都是已经实现Comparable接口的,所以对这些类型可以直接通过Arrays.sort(...)和Collections.sort(...)方法进行排序. ...

  5. php课程---建立一个简单的下拉列表框

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. IOS第二天多线程-03对列组合并图片

    ********* // 2D绘图 Quartz2D // 合并图片 -- 水印 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *) ...

  7. poj1061-青蛙的约会(扩展欧几里德算法)

    一,题意: 两个青蛙在赤道上跳跃,走环路.起始位置分别为x,y. 每次跳跃距离分别为m,n.赤道长度为L.两青蛙跳跃方向与次数相同的情况下, 问两青蛙是否有方法跳跃到同一点.输出最少跳跃次数.二,思路 ...

  8. python 安装mysql-python模块

    方式一 使用yum安装 # yum install MySQL-python 方式二 使用pip 安装 # pip install mysql-python 使用pip方式安装需要提前安装如下依赖 m ...

  9. Opensuse enable sound and mic card

    Install application pavucontrol Run pavucontrol You will see the configuration about sound card and ...

  10. JVM监控和Java应用程序调试

    JConsole.VisualVM监控JVM(JMX) JAVA_OPTS后加:-Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.managemen ...