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

题意:给你多个等差数列公差,首项和最大范围,求出哪个数出现奇数次。


分析:我们把某个数之前所有数出现过的总次数求出来,会发现会呈现偶偶偶偶偶偶偶偶偶奇奇奇奇奇奇奇奇的现象。

然后二分查询。提醒:每组数据之间可能会有多空行。


代码;

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <queue>
#define mem(p,k) memset(p,k,sizeof(p));
#define rep(i,j,k) for(int i=j; i<k; i++)
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define inf 0x6fffffff
#define ll long long
using namespace std;
const int mod=1e9+7;
int n,m,k,cur,x,y;
ll  minn,maxx;
int nex[4][2]={0,1,1,0,0,-1,-1,0};
char str[500000];
ll a[110000],b[110000],c[110000];
int jud(ll m,int len){
    ll sum=0;
    for(int i=0;i<len;i++){
        if(m<a[i])continue;
        ll k=min(m,b[i]);
        //cout<<(k-a[i]+1)/c[i]<<endl;
        sum+=(k-a[i])/c[i]+1;
    }
    //cout<<m<<"=="<<sum<<endl;
    if(sum&1)return 1;
    return 0;
}
void solve(int len){
    ll l=1,r=maxx;
    while(l<=r){
        ll m=(l+r)>>1;//cout<<l<<"==="<<r<<endl;
        if(jud(m,len)){
            r=m-1;
        }
        else l=m+1;
    }
    if(l>maxx)cout<<"no corruption"<<endl;
    else{
        ll sum=0;
        for(int i=0;i<len;i++){
            if(l>=a[i]&&l<=b[i]){
                if((l-a[i])%c[i]==0){
                        sum++;
                }//cout<<sum<<endl;
            }
        }
        cout<<l<<" "<<sum<<endl;
    }
    return ;
}
int main(){
    int le=0;
    maxx=0x9fffffff;
    while(gets(str)){
        if(strlen(str)==0){
            if(le==0)continue;
            solve(le);

            le=0;
            maxx=0x9fffffff;
            continue;
        }
        sscanf(str,"%I64d%I64d%I64d",a+le,b+le,c+le);
        le++;
    }
    if(le){
        solve(le);
    }
    return 0;
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值