zoukankan      html  css  js  c++  java
  • 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.
    ");
    45         else
    46             printf("%lld %lld
    ",l,solve(l)-solve(l-1));
    47     }
    48     
    49     return 0;
    50 }
  • 相关阅读:
    [Cerc2013]Magical GCD
    UVA 1393 Highways
    UVA 10214 Trees in a Wood
    [SDOI2010]大陆争霸
    Oracle逻辑读详解
    DBA_2PC_PENDING (转)
    oracle autotrace使用
    升级oracle 9i到10g
    VMware 虚拟机中添加新硬盘的方法(转载)
    ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var mysql (转)
  • 原文地址:https://www.cnblogs.com/Xycdada/p/6713228.html
Copyright © 2011-2022 走看看