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 }
  • 相关阅读:
    Query实例的ajax应用之二级联动的后台是采用php来做的
    关于jquery的css的一些知识
    这个代码给所有带有name属性的链接加了一个背景色
    jQuery生成一个DIV容器,ID是"rating".
    被included或者被required的文件都来自哪里呢
    msql_createdb: 建立一个新的 mSQL 数据库。
    php中调用这个功能可以在web页面中显示hello world这个经典单词
    啦啦啦测试心得
    maven命令
    robotframework使用
  • 原文地址:https://www.cnblogs.com/Xycdada/p/6713228.html
Copyright © 2011-2022 走看看