• POJ 3484


    Showstopper
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 1060   Accepted: 303

    Description

    Data-mining huge data sets can be a painful and long lasting process if we are not aware of tiny patterns existing within those data sets.

    One reputable company has recently discovered a tiny bug in their hardware video processing solution and they are trying to create software workaround. To achieve maximum performance they use their chips in pairs and all data objects in memory should have even number of references. Under certain circumstances this rule became violated and exactly one data object is referred by odd number of references. They are ready to launch product and this is the only showstopper they have. They need YOU to help them resolve this critical issue in most efficient way.

    Can you help them?

    Input

    Input file consists from multiple data sets separated by one or more empty lines.

    Each data set represents a sequence of 32-bit (positive) integers (references) which are stored in compressed way.

    Each line of input set consists from three single space separated 32-bit (positive) integers X Y Z and they represent following sequence of references: X, X+Z, X+2*Z, X+3*Z, …, X+K*Z, …(while (X+K*Z)<=Y).

    Your task is to data-mine input data and for each set determine weather data were corrupted, which reference is occurring odd number of times, and count that reference.

    Output

    For each input data set you should print to standard output new line of text with either “no corruption” (low case) or two integers separated by single space (first one is reference that occurs odd number of times and second one is count of that reference).

    Sample Input

    1 10 1
    2 10 1
    
    1 10 1
    1 10 1
    
    1 10 1
    4 4 1
    1 5 1
    6 10 1

    Sample Output

    1 1
    no corruption
    4 3

    Source

     
    由题目可知序列的前缀和必定会呈现偶偶偶偶偶奇奇奇奇奇奇,由此二分答案,然后根据前缀和判断。
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 
     6 using namespace std;
     7 
     8 #define maxn 500005
     9 
    10 typedef long long ll;
    11 
    12 char str[100];
    13 ll  X[maxn],Y[maxn],Z[maxn];
    14 int n;
    15 
    16 ll check(ll mid) {
    17         ll sum = 0;
    18         for(int i = 1; i <= n; ++i) {
    19                 if(mid < X[i]) continue;
    20                 sum += (min(mid,Y[i]) - X[i]) / Z[i] + 1;
    21         }
    22 
    23         //cout <<  "sum = " << sum << endl;
    24 
    25         return sum;
    26 }
    27 
    28 void solve() {
    29 
    30         ll l = 0 ,r = 1LL << 33;
    31 
    32         while(l < r) {
    33                 ll mid = (l + r) >> 1;
    34                 if(check(mid) % 2 == 0) l = mid + 1;
    35                 else r = mid;
    36         }
    37         if (l == 1LL << 33)
    38             puts("no corruption");
    39         else
    40             printf("%I64d %I64d
    " , l , (check(l) - check(l - 1)));
    41 
    42 
    43 }
    44 
    45 int main()
    46 {
    47     //freopen("sw.in","r",stdin);
    48     n = 0;
    49 
    50     while(gets(str)) {
    51             if(strlen(str) != 0) {
    52                     ++n;
    53                     sscanf(str,"%I64d %I64d %I64d",&X[n],&Y[n],&Z[n]);
    54                     //printf("%I64d %I64d %I64d
    ",X[n],Y[n],Z[n]);
    55             }
    56 
    57             if(strlen(str) == 0 && n) {
    58                     solve();
    59                     n = 0;
    60             }
    61     }
    62     if(n) solve();
    63     return 0;
    64 }
    View Code
  • 相关阅读:
    洛谷 P1525 关押罪犯(并查集|二分图判定&二分答案)
    洛谷 P1948 [USACO08JAN]Telephone Lines S(贪心+最短路)
    洛谷 P1315 观光公交(贪心+模拟)
    洛谷 P3258 [JLOI2014]松鼠的新家(树上差分)
    【NOIP2001】统计单词个数
    【洛谷习题】皇后游戏
    【洛谷习题】木棍加工
    【SDOI2008】仪仗队
    【洛谷习题】末日的传说
    【洛谷习题】又是毕业季I
  • 原文地址:https://www.cnblogs.com/hyxsolitude/p/3619890.html
Copyright © 2020-2023  润新知