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;
    }
    
  • 相关阅读:
    JDBC 处理sql查询多个不确定参数
    网页跳转方法总结
    图片上传,直接在网页中显示(支持IE,谷歌,火狐浏览器)
    Oracle报 ORA-00054资源正忙的解决办法
    js对cookie的操作:读、写、删
    认识SignalR
    sql 查询结果用逗号分隔到一列里
    异步编程之await的使用
    应用程序池
    判断list重复扩展方法
  • 原文地址:https://www.cnblogs.com/orion7/p/7821497.html
Copyright © 2011-2022 走看看