zoukankan      html  css  js  c++  java
  • POJ 3484 Showstopper(二分)

    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+2Z, X+3Z, …, X+KZ, …(while (X+KZ)<=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

    题意:

    N个等差数列,初项X_i,末项Y_i,公差Z_i,求出现奇数次的数?

    题解:

    输入很恶心。。题目保证出现奇数次的数只有一个,假设J是输出奇数次的那个数,那么小于J的所有输出的数的个数之和就为偶数,大于等于J的所有输出的数的个数之和为奇数 。如:偶偶偶偶偶偶奇奇奇第一个奇数就是J。那么二分查找即可。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    const int maxn=1e5+5;
    using namespace std;
    typedef long long LL;
    LL x[maxn],y[maxn],z[maxn];
    int cnt;
    char str[maxn];
    LL check(LL mid)
    {
        LL sum=0;
        for(int i=0;i<cnt;i++)
        {
            if(mid<x[i])
                continue;
            LL t=min(mid,y[i]);
            sum+=(t-x[i])/z[i]+1;
        }
        return sum;
    }
    void solve()
    {
        cnt=0;
        x[0]=0;
        sscanf(str,"%lld%lld%lld",&x[cnt],&y[cnt],&z[cnt]);
        cnt++;
        if(!x[0])
            return ;
        while(gets(str)&&str[0])
            sscanf(str,"%lld%lld%lld",&x[cnt],&y[cnt],&z[cnt]),cnt++;
        LL lb=0,ub=1LL<<32;
        while(ub-lb>1)
        {
            LL mid=(lb+ub)>>1;
            if(check(mid)%2)
                ub=mid;
            else
                lb=mid;
        }
        if(lb+1==(1LL<<32))
            cout<<"no corruption"<<endl;
        else
            cout<<ub<<' '<<check(ub)-check(ub-1)<<endl;
    }
    int main()
    {
        while(gets(str))
            solve();
        return 0;
    }
    
  • 相关阅读:
    在已经安装的nginx上,增加ssl模块
    apache ab压力测试报错(apr_socket_recv: Connection reset by peer (104))
    ab和jmeter进行GET/POST压力测试的使用心得和比较
    linux历史命令查找快捷方式
    HDFS的dfs.replication不同验证
    Set replication in Hadoop
    RVM 安装 Ruby
    Fluentd初探 简介与安装
    Flunetd 用于统一日志记录层的开源数据收集器
    Custom partition assignment and migration kafka集群扩充迁移指定partition
  • 原文地址:https://www.cnblogs.com/orion7/p/7821497.html
Copyright © 2011-2022 走看看