Flyer(二分 HDU4768)
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)的更多相关文章
- HDU4768:Flyer [ 二分的奇妙应用 好题 ]
传送门 Flyer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 4768 Flyer 二分
思路:由于最多只有一个是奇数,所以二分枚举这个点,每次判断这个点的左边区间段所有点的和作为 二分的依据. 代码如下: #include<iostream> #include<cstd ...
- HDU 4768 Flyer(二分)
题目链接: 传送门 Flyer Time Limit: 1000MS Memory Limit: 32768 K Description The new semester begins! Di ...
- HDU 4768 Flyer (2013长春网络赛1010题,二分)
Flyer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 4768 Flyer【二分】||【异或】
<题目链接> <转载于 >>> > 题目链接: n个社团派发传单,有a,b,c三个参数,派发的规则是,派发给序号为a,a+c....a+k*c,序号要求是小 ...
- hdu4768二分答案
/* 如果发的传单是偶数,那么所有人都收到双数张. 仅考虑发了单数张传单,二分答案x,如果x左边是偶数,那么答案在右侧,如果x左边是奇数,那么答案在左侧 */ #include<iostream ...
- [hdu4768]二分
http://acm.hdu.edu.cn/showproblem.php?pid=4768 题意:n个传单分别发给编号为ai, ai + ci, ai + 2 * ci, .. , ai + k * ...
- hdu4768 非常规的二分
题意: n个社团给同学发传单,同学一共有1--2^31这么多,每个社团有三个数A ,B ,C ,只有 满足 A ,A + C ,A + C + C ...A + KC <= B 的学 ...
- HDOJ 4768 Flyer
二分.... Flyer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
随机推荐
- HTML 几种特别分割线特效
一.基本线条 二.特效(效果并不是孤立的,可相互组合)1.两头渐变透明:<HR style="FILTER: alpha(opacity=100,finishopacity=0,sty ...
- DOS运行命令
运行命令主要是DOS操作系统的运行方式.DOS时代的时候,为了方便用户的操作,微软公司将一些常用的命令,如DIR,CD等命令全部集成在系统里面. 基本定义 对于DOS来说是一个很大的优点.而存放这些内 ...
- mysql view(视图)
一,什么是视图 视图是存放数据的一个接口,也可以说是虚拟的表.这些数据可以是从一个或几个基本表(或视图)的数据.也可以是用户自已定义的数据.其实视图里面不存放数据的,数据还是放在基本表里面,基本表里面 ...
- Centos7 创建个文件 thread 怪现象
我在~下创建个目录thread, 然后写了个程序, 再执行, 提示需要权限, 之后我重命名下文件的名字, 重新编译下, 就可以正常执行了.
- 【iCore3 双核心板】例程五:SYSTICK定时器实验——定时点亮LED
实验指导书及代码包下载: http://pan.baidu.com/s/1eQsKcEY iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...
- find命令查找文件,并排除相应路径
find / -path "/exclude/" -prune -o -name "lsof" -print 查找根目录下文件,并排除/exclude路径
- Java集合框架使用总结
Java集合框架使用总结 前言:本文是对Java集合框架做了一个概括性的解说,目的是对Java集合框架体系有个总体认识,如果你想学习具体的接口和类的使用方法,请参看JavaAPI文档. 一.概述数据结 ...
- 一个关于Delphi XML处理单元的BUG
使用delphi的XML处理单元 XMLDoc XMLIntf 在获取XML文本内容的时候, 高版本的Delphi会丢失编码描述....在D7上却是正常的, 下面是测试源码: procedure TF ...
- linq判断集合是否为空的方法
Enumerable.Any 扩展方法可以判断集合为空: 如果不为空 if (!source.Any()) { //... }
- Android You need to use a Theme.AppCompat theme (or descendant) with this activity.
错误描述为:java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with ...