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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值