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. 对Oracle数据库坏块的理解

    1.物理坏块和逻辑坏块 在数据库中有一个概念叫做数据块的一致性,Oracle的数据块的一致性包括了两个层次:物理一致性和逻辑一致性,如果一个数据块在这两个层次上存在不一致性,那就对应到了我们今天要要说 ...

  2. zendFream 中的用到了Ajax(其中有搜索)分页

    最近在用ZendFreamwork开发一个后台,其中用到了分页,ZendFreamwork自带的分页挺好用的,可是我其中用到了Ajax的局部刷新,在加上一些搜索条件,所以分页有点无头绪了.下面我来介绍 ...

  3. param STRING $username 要检查的用户名

    检查用户名是否符合规定 两位以上的字母,数字,或者下划线,代码如下: php;auto-links:false;">/** * 检查用户名是否符合规定 * * @param STRIN ...

  4. java之main函数(笔记)

    1.标准的main函数形式 对于main函数,只要是 public static void main(String[] args) public static void main(String... ...

  5. Ubuntu Linux上安装配置Mysql

    一.安装: 三种安装方式: 1. 从网上安装 sudo apt-get install mysql-server.装完已经自动配置好环境变量,可以直接使用mysql的命令. 注:建议将/etc/apt ...

  6. WPF 打开文件、文件夹

    打开文件代码: OpenFileDialog openFileDialog = new OpenFileDialog();            openFileDialog.Title = &quo ...

  7. do put in ruby

    apikey: XO.apikeys.cms, data: { favoriteItems: [{ UserId: SaveToFavoriteVar.content.FavoriteItem.Use ...

  8. Bootstrap 弹出框和警告框插件

    一.弹出框 弹出框即点击一个元素弹出一个包含标题和内容的容器. //基本用法 <button class="btn btn-lg btn-danger" type=" ...

  9. 学习mysql

    一 概述 1.什么是数据库 数据库就是数据的仓库. mysql是对数据库进行存储和指令操作的软件.这类软件成为数据管理系统Database Management System. 2.mysql的安装和 ...

  10. [LeetCode]题解(python):116 Populating Next Right Pointers in Each Node

    题目来源 https://leetcode.com/problems/populating-next-right-pointers-in-each-node/ Given a binary tree ...