POJ3484_Showstopper_前缀和思想&&二分

Showstopper
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2138 Accepted: 644

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


给出若干个数列,在所有这些数列中,大部分元素都出现了偶数次,最多只有一个元素出现了奇数次。若存在一个出现了奇数次的元素,输出这个元素和它出现的次数。如果不存在,输出no corruption。其中每一个数列以X Y Z 的形式给出,X, X+Z, X+2*Z, X+3*Z, …, X+K*Z, …(while (X+K*Z)<=Y). 


这里有一个把问题转化为前缀和的技巧。假设出现了次的这个数为 O,则O之前的前缀和都是偶数,O之后的前缀和都是基数。因此可以用二分的方法做。


#include<cstdio>
#include<iostream>
#include<cstring>

using namespace std;
typedef long long ll;

const ll inf = 0x8f8f8f8f8f;
const ll maxn = 100000;
char s[100];
int squ;
ll X[maxn], Y[maxn], Z[maxn];

ll Getsum(ll x)
{
	ll sum = 0;

	for(int i= 0; i< squ; i++){
		if(x < X[i]) continue;
		sum += (min(Y[i], x) - X[i]) / Z[i] + 1;
	}

	return sum;
}

bool Judge(ll x)
{
	ll sum = Getsum(x);

	if(sum & 1 == 1) return true;
	return false;
}

void solve ()
{
	ll lb = 1, ub = inf;
	ll ans = -1;

	while(lb <= ub){

		ll md = (ub + lb) >> 1;

		if(Judge(md)) ans = md, ub = md - 1;
		else lb = md + 1;
	}

	if(ans == -1) cout << "no corruption\n";
	else cout << ans << " " << Getsum(ans) - Getsum(ans-1) << endl;
}

int main ()
{
	while(gets(s) != NULL){

		if(strlen(s) == 0){
			if(squ == 0) continue;

			solve();

			squ = 0;
		}

		else{
			sscanf(s, "%lld %lld %lld", X+squ, Y+squ, Z+squ);//敲黑板
			squ ++;
		}

	}

	if(squ != 0) solve();

	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值