Showstopper - POJ 3484 二分

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
题目意思:给出一组x,y,z 每组包含一个集合{x+k*z<=y,k=0,1,2,3...}, 所有集合中只有一个数出现奇数次或者全部出现偶数次,如果有数出现奇数次,输出那个数以及出现的次数,否则输出 no corruption

解题思路:因为只可能有一个数出现奇数次,假设为x,所有数出现次数的和依次为  偶 偶 偶 奇(x) 奇  奇 奇  x之前为偶数,x之后为奇数,而所有数出现的次数可以根据公式直接算出,再根据这个单调性二分出答案。

代码:

#include <cstdio>
#include <iostream>
#include <sstream>
#include <cstring>
#include <vector>
using namespace std;

#define inf 0xffffffff
#define maxn 300000
/
char s[100];
struct Node{
    int x,y,z;
};
vector<Node> vec;
int c[maxn];
/
long long sum(int m){
    long long cnt = 0;
    for(int i=0;i<vec.size();i++){
        if(m>=vec[i].y) cnt += c[i];
        else if(m>=vec[i].x) cnt += (m-vec[i].x)/vec[i].z +1;
    }
    return cnt;
}

void solve(){
    long long tmp = 0;
    for(int i=0;i<vec.size();i++){
        c[i] = (vec[i].y-vec[i].x)/vec[i].z+1;
        tmp += c[i];
    }
    if(!(tmp&1)){
        printf("no corruption\n");
        return;
    }
    unsigned int l=0, r = inf,mid;
    while(l<r){
        mid = (l+r) >>1;
        if(sum(mid)&1) r = mid;
        else l = mid+1;
    }
    printf("%d %d\n",r,sum(r)-sum(r-1));
}
int main(){
    bool flag = false;
    Node node;
    while(gets(s)){
        if(strlen(s)==0 && flag) {
            solve();
            flag = false;
            vec.clear();
        }else if(strlen(s)>0){
            stringstream ss(s);
            ss >> node.x >> node.y >> node.z;
            vec.push_back(node);
            flag = true;
        }
    }
    solve();
    return 0;
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值