• POJ 3484 二分


    Showstopper

    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

    题意:给出多组数据,每组间由多行空行隔开,每组数据包含多个数列,求在所有数列中出现次数为奇数次的数字。
    思路:二分答案,求x以内的数字的总个数sum(x),当sum(x)%2==1 时表明 目标数字k<=x,否则k>x,以此来二分。
    代码:
     1 //#include"bits/stdc++.h"
     2 #include<sstream>
     3 #include<iomanip>
     4 #include"cstdio"
     5 #include"map"
     6 #include"set"
     7 #include"cmath"
     8 #include"queue"
     9 #include"vector"
    10 #include"string"
    11 #include"cstring"
    12 #include"time.h"
    13 #include"iostream"
    14 #include"stdlib.h"
    15 #include"algorithm"
    16 #define db double
    17 #define ll long long
    18 #define vec vector<ll>
    19 #define mt  vector<vec>
    20 #define ci(x) scanf("%d",&x)
    21 #define cd(x) scanf("%lf",&x)
    22 #define cl(x) scanf("%lld",&x)
    23 #define pi(x) printf("%d
    ",x)
    24 #define pd(x) printf("%f
    ",x)
    25 #define pl(x) printf("%lld
    ",x)
    26 //#define rep(i, x, y) for(int i=x;i<=y;i++)
    27 #define rep(i, n) for(int i=0;i<n;i++)
    28 const int N   = 1e6 + 5;
    29 const int mod = 1e9 + 7;
    30 const int MOD = mod - 1;
    31 const int inf = 0x3f3f3f3f;
    32 const db  PI  = acos(-1.0);
    33 const db  eps = 1e-10;
    34 using namespace std;
    35 ll x[N],y[N],z[N],cnt=0;
    36 char s[N];
    37 ll cal(ll k)
    38 {
    39     ll ans=0;
    40     for(int i=0;i<cnt;i++){
    41         if(k<x[i]) continue;
    42         ans+=(min(y[i],k)-x[i])/z[i]+1;//统计小于等于k的数有多少个
    43     }
    44     return ans;
    45 }
    46 ll solve()
    47 {
    48     ll l=-1,r=(1ll<<35),ans=-1;
    49     while(l<=r)
    50     {
    51         ll mid=(l+r)/2;
    52         if(cal(mid)%2==1) r=mid-1,ans=mid;//若为奇数个则目标数字x<=mid
    53         else l=mid+1;//否则目标数字x>mid
    54     }
    55     return ans;
    56 }
    57 int main()
    58 {
    59     cnt=0;
    60     while(gets(s)!=NULL){
    61         if(strlen(s)==0)
    62         {
    63             if(!cnt) continue;
    64             ll ret=solve();
    65             if(ret==-1) puts("no corruption");
    66             else printf("%lld %lld
    ",ret,cal(ret)-cal(ret-1));
    67             cnt=0;
    68         }
    69         else
    70         {
    71             sscanf(s,"%lld%lld%lld",&x[cnt],&y[cnt],&z[cnt]);//必须用sscanf?
    72             cnt++;
    73         }
    74     }
    75     if(cnt)
    76     {
    77         ll ret=solve();
    78         if(ret==-1) puts("no corruption");
    79         else printf("%lld %lld
    ",ret,cal(ret)-cal(ret-1));
    80     }
    81     return 0;
    82 }
  • 相关阅读:
    ios7 苹果原生二维码扫描(和微信类似)
    ios7之后 根据UILabel的文字计算frame的方法
    [Luogu1944] 最长括号匹配
    [bzoj3916] friends
    [NOIp2006] 能量项链
    [NOIp2003] 加分二叉树
    [Luogu1353] 跑步Running
    [Luogu2214] Mooo Moo S
    [POJ2452] Sticks Problem
    [POJ2406] Power Strings
  • 原文地址:https://www.cnblogs.com/mj-liylho/p/8763823.html
Copyright © 2020-2023  润新知