• 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;
    }
    
  • 相关阅读:
    代码互改
    第一次个人编程作业
    第一次博客
    个人总结
    第三次个人作业--用例图设计
    第二次结对作业
    第一次结对作业
    记录浏览他人代码
    中文编程作业
    第一篇随笔
  • 原文地址:https://www.cnblogs.com/orion7/p/7821497.html
Copyright © 2020-2023  润新知