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. WPF 程序启动显示为通知区域的图标方法

    首先需要引用  System.Windows;  System.Drawing; public partial class MainWindow : Window { public MainWindo ...

  2. 设置Oracle时间格式

    ORACLE的DATE类型的显示方式取决于NLS_DATE_FORMAT初始化参数NLS_DATE_FORMAT参数可以在以下几个级别设置1.数据库级别——如果希望所有人都看到某种格式的数据,则在SQ ...

  3. 使用JDBC批量保存数据(JdbcDaoSupport,JdbcTemplete)

    最近做的一个项目中用到了Hibernate的,然后数据库批量插入数据的时候就使用到了hibernate的批处理,但是效率比较低,看网上说还有一些限制,要禁止二级缓存,还要多一个batch_size的配 ...

  4. 面试之servlet、过滤器、监听器

    servlet.过滤器.监听器servlet是Java中WEB请求和响应的容器servlet的运行需要在类似tomcat容器中,一个 Web 应用对应一个 Context 容器,也就是 Servlet ...

  5. 类 class

    <?php class Person{ //定义一个类 public $name; //定义属性 public $age; function say(){ //定义办法 echo "m ...

  6. Ajax Post 与 Get 实例

    Ajax的POST实例,index.html <html> <head> <script type="text/javascript"> fun ...

  7. Maven入门系列(二)--设置中央仓库的方法

    原文地址:http://www.codeweblog.com/maven入门系列-二-设置中央仓库的方法/ Maven仓库放在我的文档里好吗?当然不好,重装一次电脑,意味着一切jar都要重新下载和发布 ...

  8. 未找到arm-linux-gcc解决办法

    sudo tar jxvf arm-linux-gcc.4.3.3.tar.bz2 export PATH=$PATH:/usr/local/arm/2.95.3/bin #/usr/local/ar ...

  9. java环境搭建系列:JDK环境变量详细配置

    学习java语言,编写java程序,运行java程序,都离不开Java环境的支持,最重要的就是安装JDK,JDK给我提供了java程序的开发环境和运行环境.为了让java程序放在电脑的任意位置都可以执 ...

  10. CSS权威指南 - 基础视觉格式化 3

    行内替换元素 替换元素比如图片的高度比line-height大,并不会影响整个文字段落的line-height,会让有图片那一行框的高度可以容纳这个图片. 这个图片依然有一个line-height,和 ...