HDU 4768 Flyer(二分)
题目链接: 传送门
Flyer
Time Limit: 1000MS Memory Limit: 32768 K
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+2C_i,…A_i+kC_i (A_i+kC_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
解题思路:
有n个社团,第i个社团有3个数a[i] b[i] c[i] 每个社团给学号小于等于b[i]且为a[i],a[i]+c[i]..a[i]+k*c[i]的人发传单。最多只有一个人被发到奇数次传单,求出他的编号和传单数目。如果没人,就输出 DC Qiang is unhappy.。
如果有人收到奇数次传单,则所有社团发传单的总数显然是奇数。所以我们二分枚举传单总数。每次对于二分的结果mid检查学号[0,mid]区间内收到的传单总数是不是奇数。 如果是,那结果肯定在[0,mid]内,否则就在[mid+1,2^31]内,继续二分。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const long long INF = (1LL << 31);
struct node{
LL a,b,c;
};
node p[20005];
int N;
bool OK(LL x)
{
LL sum = 0,tmp = 0;
for (int i = 0;i < N;i++)
{
tmp = min(x,p[i].b);
if (tmp >= p[i].a)
{
sum += (tmp - p[i].a)/p[i].c + 1;
}
}
if (sum & 1)
return true;
else
return false;
}
int main()
{
while (~scanf("%d",&N))
{
LL maxx = 0,minn = INF,sum = 0;
memset(p,0,sizeof(p));
for (int i = 0;i < N;i++)
{
scanf("%I64d%I64d%I64d",&p[i].a,&p[i].b,&p[i].c);
maxx = max(maxx,p[i].b);
minn = min(minn,p[i].a);
sum += (p[i].b - p[i].a)/p[i].c + 1;
}
//cout << minn << " " << maxx << endl;
if (!(sum & 1))
{
printf("DC Qiang is unhappy.\n");
continue;
}
LL left = minn,right = maxx;
while (left < right)
{
LL mid = left +((right-left)>>1);
if (OK(mid))
{
right = mid;
}
else
{
left = mid + 1;
}
}
//cout << left << " " << right << endl;
LL cnt = 0;
for (int i = 0;i < N;i++)
{
if (right >= p[i].a && right <= p[i].b && (right - p[i].a) % p[i].c == 0)
{
cnt++;
}
}
printf("%I64d %I64d\n",right,cnt);
}
return 0;
}
HDU 4768 Flyer(二分)的更多相关文章
- hdu 4768 Flyer 二分
思路:由于最多只有一个是奇数,所以二分枚举这个点,每次判断这个点的左边区间段所有点的和作为 二分的依据. 代码如下: #include<iostream> #include<cstd ...
- 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,序号要求是小 ...
- HDU 4768 Flyer(二分法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4768 题目大意:每组数据有n行输入,每行有三个数A.B.C,A<=B且小于2^32,从A到B每隔 ...
- 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 ...
- HDU 4768 (二分区间---涨姿势)
题意:告诉n组A,B,C,按照A + k * C生成等差数列,问这n组数列中哪个数字出现了奇数次以及出现了几次,题目保证最多只会出现一个这种数字. 分析:读完题并没有思路,后来知道是二分区间,枚举是哪 ...
- HDU 4768: Flyer
题意: 有N个社团,每个社团三个属性A,B,C,表示会向编号A+k*C的同学发传单(k=0,1,2... && A+k*C <= B).题目保证最多有一个人收到的传单数是奇数. ...
- hdu 4768 Flyer (异或操作的应用)
2013年长春网络赛1010题 继巴斯博弈(30分钟)签到后,有一道必过题(一眼即有思路). 思路老早就有(40分钟):倒是直到3小时后才被A掉.期间各种换代码姿态! 共享思路: unlucky st ...
- HDU4768:Flyer [ 二分的奇妙应用 好题 ]
传送门 Flyer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- Qt学习笔记 ListWidget的增删改
学习了一下ListWidget控件的使用,做一个小功能增删改 先把代码分解最后给出完整代码 在窗体上添加一个ListWidget 一个Horizontal Specer和 三个PushButton ...
- web 前端常用组件【03】Bootstrap Multiselect
实际的项目网站中或多或少的或用到多选框,我选用的一款是 Bootstrap Multiselect. 官方文档:http://www.kuitao8.com/demo/20140224/1/boots ...
- Adblock Plus for firefox
关于 Adblock Plus for firefox(以下简称 ABP)的一些笔记. 安装好 ABP,将如下代码保存为 html 文件,然后在 firefox 中打开: <p id=" ...
- async 更优雅异步体验
上一篇<让 Generator 自启动>介绍了通过起动器让 Generator 跑起来,而本篇采用 async 实现更优雅的异步编程. 从例子开始 借用上一篇例子中的例子说起. funct ...
- Code First操作Mysql数据库
前面博客也讲了,自己做一个网站,选用的是MVC+EF Code First+MySql+EasyUI,先说下技术选型.一.为什么选择MVC? 因为之前自己做的系统大部分是webForm,MVC的之前也 ...
- 代码重构之 —— 一堆if、esle 逻辑的处理
这几天,接手一个同事的代码,关于微信接口开发的,那一堆的 if,看得哥蛋痛了,这个毛病也是很多新手容易犯的,所以特地把这次重构写出来. 下面来我们看看这个代码的问题所在,if else 里面的代码块逻 ...
- 利用PhotoShop将Font-Awesome转为图片格式
介绍如何将Font-Awesome等字体图标转换为图片格式,使用PHOTPSHOP很简单. 网上找了很多,都比较麻烦.别问为什么要这么做,因为你还没遇到需要的时候. 下载Font-Awesome字体库 ...
- GWT-Dev-Plugin(即google web toolkit developer plugin)for Chrome的安装方法
如果你想要在Chrome中进行GWT调试,需要安装“gwt developer plugin for chrome”,但是普通安装模式下,会提示: This application is not su ...
- nginx启动、重启、关闭
一.启动 cd usr/local/nginx/sbin ./nginx 二.重启 更改配置重启nginx kill -HUP 主进程号或进程号文件路径 或者使用 cd /usr/local/ngin ...
- jQuery报 SyntaxError: expected expression, got '<'错误
这有什么可奇怪的,这个问题是表达式未能按照预期结束,说白了就是你少写分号了. 你肯定是语法错了,仔细查看一下提示错误的那一行和它的附近,是不是因为疏忽大意出错了. 再给你的建议,不要觉得某个分号可以省 ...