• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

HDU 4768 Flyer 二分统计(2013 ACM/ICPC Asia Regional Changchun Online J)

你为何这么叼!
 

Flyer

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


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
 

Recommend
liuyiding
 
return sum==0;的写法只能用bool型!why的说!
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5 #define ll __int64
 6 #define maxn 200005
 7 ll a[maxn],b[maxn],c[maxn],k[maxn];
 8 int n;
 9 ll l,r;
10 bool check(ll x){
11     ll sum=0;
12     for(int i=0;i<n;i++){
13         ll t=x-a[i];
14         if(t>=0){
15             t=t/c[i];
16             sum+=min(t+1,k[i]);
17         }
18     }
19     return sum%2==0;
20 }
21 ll find(ll tl,ll tr){
22     while(tl<tr){
23         ll m=(tl+tr)>>1;
24         if(check(m))tl=m+1;
25         else tr=m;
26     }
27     return tr;
28 }
29 int solve(ll x){
30     int sum=0;
31     for(int i=0;i<n;i++){
32         ll t=x-a[i];
33         if(t%c[i]==0&&t>=0&&t<=b[i]-a[i])sum++;
34     }
35     return sum;
36 }
37 int main(){
38     while(~scanf("%d",&n)){
39         l=(ll)1<<32;
40         r=-1;
41         ll sum=0;
42         for(int i=0;i<n;i++){
43             scanf("%I64d%I64d%I64d",&a[i],&b[i],&c[i]);
44             ll t=k[i]=(b[i]-a[i])/c[i]+1;
45             if(a[i]<l)l=a[i];if(a[i]+(t-1)*c[i]>r)r=a[i]+(t-1)*c[i];
46             sum+=k[i];
47         }
48         if(sum&1){printf("DC Qiang is unhappy.\n");continue;}
49         r=find(l,r);
50         printf("%I64d %d\n",r,solve(r));
51     }
52     return 0;
53 }
View Code 2013-10-03 09:27:53 

 

posted @ 2013-10-03 09:27  HaibaraAi  阅读(111)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3