zoukankan      html  css  js  c++  java
  • HDU 4768 Flyer (2013长春网络赛1010题,二分)

    Flyer

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


    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
     
    Recommend
    liuyiding
     

    因为最多一个奇数的,所以总数是奇数的。

    二分区间就可以了。

    比赛时候二分的 l,r都是int存的,导致算mid = (l+r)/2的时候溢出了,TAT

    这样TLE了好久,我艹。。。。。

    水题一发

     1 /* ***********************************************
     2 Author        :kuangbin
     3 Created Time  :2013/9/28 星期六 13:00:24
     4 File Name     :2013长春网络赛1010.cpp
     5 ************************************************ */
     6 
     7 #pragma comment(linker, "/STACK:1024000000,1024000000")
     8 #include <stdio.h>
     9 #include <string.h>
    10 #include <iostream>
    11 #include <algorithm>
    12 #include <vector>
    13 #include <queue>
    14 #include <set>
    15 #include <map>
    16 #include <string>
    17 #include <math.h>
    18 #include <stdlib.h>
    19 #include <time.h>
    20 using namespace std;
    21 
    22 const int MAXN = 20010;
    23 long long A[MAXN];
    24 long long B[MAXN];
    25 long long C[MAXN];
    26 int n;
    27 inline long long calc(long long  start,long long add,long long end)
    28 {
    29     return (end-start+1 + add-1)/add;
    30 }
    31 inline bool check(long long l,long long r)
    32 {
    33     long long sum = 0;
    34     for(int i = 0;i < n;i++)
    35     {
    36         long long end = min(B[i],r);
    37         if(end < A[i])continue;
    38         if(l >end)continue;
    39         long long s1;
    40         s1 = calc(A[i],C[i],end);
    41         if(l <= A[i])sum += s1;
    42         else sum += s1 - calc(A[i],C[i],l-1);
    43 
    44     }
    45     if(sum % 2 == 0)return false;
    46     return true;
    47 }
    48 long long ttt(long long l,long long r)
    49 {
    50     long long sum = 0;
    51     for(int i = 0;i < n;i++)
    52     {
    53         long long end = min(B[i],r);
    54         if(end < A[i])continue;
    55         if(l > end)continue;
    56         long long s1,s2;
    57         s1 = calc(A[i],C[i],end);
    58         if(l <= A[i])sum += s1;
    59         else sum += s1 - calc(A[i],C[i],l-1);
    60 
    61     }
    62     return sum;
    63 }
    64 int main()
    65 {
    66     //freopen("in.txt","r",stdin);
    67     //freopen("out.txt","w",stdout);
    68     while(scanf("%d",&n) == 1 && n)
    69     {
    70         long long l = 100000000000LL, r = 0;
    71         for(int i = 0;i < n;i++)
    72         {
    73             scanf("%I64d%I64d%I64d",&A[i],&B[i],&C[i]);
    74             l = min(l,A[i]);
    75             r = max(r,B[i]);
    76         }
    77         if(check(l,r) == false)
    78         {
    79             printf("DC Qiang is unhappy.
    ");
    80             continue;
    81         }
    82         while(l < r)
    83         {
    84             long long mid = (l+r)/2;
    85             if(check(l,mid))
    86             {
    87                 r = mid;
    88             }
    89             else l = mid+1;
    90         }
    91         printf("%d %d
    ",(int)l,(int)ttt(l,l));
    92     }
    93     return 0;
    94 }
  • 相关阅读:
    HDU4411 最小费用流
    HDU5934 强连通分量
    一个问题
    SAP模板
    KMP模板
    ]C#中执行SQL文件脚本的代码(非常有用)
    C#调用非托管程序5种方式
    [转]C#中的静态常量(const)和动态常量(static和readonly)用法和区别
    [转]C#开发命名规范总结整理
    [转]关于同步方法里面调用异步方法的探究
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3345035.html
Copyright © 2011-2022 走看看