hdu 4768 二分

Flyer

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3148    Accepted Submission(s): 1174

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

不是很有思路,大神的代码

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<math.h>
 4 #include<iostream>
 5 #include<algorithm>
 6 using namespace std;
 7 #define ll long long
 8 #define L 20005
 9
10 using namespace std;
11
12 ll a[L],b[L],c[L],l,r,n;
13
14 ll solve(ll mid)
15 {
16     ll k,sum = 0;
17     int i;
18     for(i = 0; i<n; i++)
19     {
20         k = min(mid,b[i]);
21         if(k>=a[i])
22             sum+=(k-a[i])/c[i]+1;
23     }
24     return sum;
25 }
26
27 int main()
28 {
29     int i,j;
30     while(~scanf("%lld",&n))
31     {
32         for(i = 0; i<n; i++)
33             scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
34         l = 0,r = 1LL<<31;
35         cout<<r<<endl;
36         ll mid;
37         while(l<r)
38         {
39             mid = (l+r)/2;
40             if(solve(mid)%2) r = mid;
41             else l = mid+1;
42         }
43         if(l == 1LL<<31)
44             printf("DC Qiang is unhappy.\n");
45         else
46             printf("%lld %lld\n",l,solve(l)-solve(l-1));
47     }
48
49     return 0;
50 }
时间: 2024-10-29 09:55:43

hdu 4768 二分的相关文章

HDU 4768 Flyer (二分)

OJ题目:click here~~ 题目分析:n个[a  b] 区间,对于i 属于[a  b]  ,从a开始,间隔c ,即i = a , i = a + c , i = a + 2*c -- 将x[ i ] 加1 ,x[ i ] 初值为0 . 已知最多只有一个x[ i ] 为奇数.找到这个i , 和这个奇数. 由于最多只有一个奇数,且奇数 + 偶数 = 奇数.用二分夹逼出这个奇数的位置.找到这个位置,再计算这个奇数就很容易了. AC_CODE const int maxn = 20002; LL

hdu 4768 Flyer(二分查找)

Flyer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1537    Accepted Submission(s): 552 Problem Description The new semester begins! Different kinds of student societies are all trying to adv

hdu 2255 二分图带权匹配 模板题

模板+注解在 http://blog.csdn.net/u011026968/article/details/38276945 hdu 2255 代码: //KM×î´ó×îСƥÅä #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; #define INF 0x0fffffff const int MAXN

Hdu 2389 二分匹配

题目链接 Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Others)Total Submission(s): 2644    Accepted Submission(s): 823 Problem Description You’re giving a party in the garden of your villa by the sea. T

hdu 4737 二分或暴力

http://acm.hdu.edu.cn/showproblem.php?pid=4737 Problem Description There are n numbers in a array, as a0, a1 ... , an-1, and another number m. We define a function f(i, j) = ai|ai+1|ai+2| ... | aj . Where "|" is the bit-OR operation. (i <= j)

HDU 3656 二分+dlx判定

Fire station Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1308    Accepted Submission(s): 434 Problem Description A city's map can be seen as a two dimensional plane. There are N houses in

hdu 4768 Flyer【二分】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4768 题意:学校有N个社团,新学期开始之际这N个社团发传单,它们发 传单是有规律的,有三个数组A[maxn],B[maxn],C[maxn],第i个设 团值发给编号为x的同学,其中x=A[i]+k*C[i]且k为整数,x小于等于 B[i];学校学生标号1~2^31,求那个同学收到传单数为奇数和这位同学 收到的传单数目,题目保证最多有一位同学收到传单为奇数. 分析:题目保证的那句话很重要,由于学生的数

HDU 4768 (二分区间)

题意:告诉n组A,B,C,按照A + k * C生成等差数列,问这n组数列中哪个数字出现了奇数次以及出现了几次,题目保证最多只会出现一个这种数字. 分析:读完题并没有思路,后来知道是二分区间,枚举是哪个数字出现了奇数次,算该数字之前一共有几个数字,如果是奇数个,说明答案就在[L , Mid]中. PS:之前用二分只是枚举具体要求的数字,原来枚举区间也可以.二分的时候 l = mid + 1,r = mid ;(一开始r = mid + 1,l = mid就无限循环,手算并没有错啊?很奇怪...)

hdu 4768 异或运算

http://acm.hdu.edu.cn/showproblem.php?pid=4768 貌似非常多人是用的二分 可是更好的做法貌似还是异或 对于第k个人.假设他接到偶数个传单.那么异或的结果还是0 就是说op记录全部收到传单的人次的总的异或值.那么由于仅仅有一个是收到奇数次.所以异或值就是他的编号,至于收到几次,在O(n)能够计算 //#pragma comment(linker, "/STACK:102400000,102400000") #include <cstdio