POJ3484-Showstopper

来源:互联网 发布:ubuntu rvm ruby安装 编辑:程序博客网 时间:2024/05/29 12:08

Showstopper
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2166 Accepted: 648

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 12 10 11 10 11 10 11 10 14 4 11 5 16 10 1

Sample Output

1 1no corruption4 3

Source

Southeastern Europe 2007


题意:n个等差数列,初项X_i,末项Y_i,公差Z_i,求出现奇数次的数

解题思路:二分出现了奇数次的数,不过这题一直RE,最后一组数据不输入空行,学了一种新的输入方式


#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <queue>#include <cmath>#include <map>#include <bitset>#include <set>#include <vector>#include <functional>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;LL x[2000000],y[2000000],z[2000000],cnt;char ch[1000];/*void change(char s[]){    int len=strlen(s),i=0;    while(ch[i]!=' ')    {        x[cnt]=x[cnt]*10+s[i++]-'0';    }    i++;    while(ch[i]!=' ')    {        y[cnt]=y[cnt]*10+s[i++]-'0';    }    i++;    while(i<len)    {        z[cnt]=z[cnt]*10+s[i++]-'0';    }    cnt++;}*/bool check(LL k){    LL sum=0;    for(int i=1; i<cnt; i++)    {        if(k>=x[i])        {            LL kk=min(y[i],k);            sum+=(kk-x[i])/z[i]+1;        }    }    if(sum&1) return 1;    else return 0;}void solve(){    LL l=1,r=0x7FFFFFFF,ans=-1;    while(l<=r)    {        LL mid=(l+r)/2;        if(check(mid))        {            ans=mid,r=mid-1;        }        else l=mid+1;    }    if(ans==-1) printf("no corruption\n");    else    {        int sum=0;        for(int i=1; i<cnt; i++)        {            if(ans>=x[i]&&ans<=y[i]&&(ans-x[i])%z[i]==0)                sum++;        }        printf("%lld %d\n",ans,sum);    }}int main(){    cnt=1;    /*memset(x,0,sizeof x);    memset(y,0,sizeof y);    memset(z,0,sizeof z);*/    while(gets(ch))    {        if(ch[0]!='\0') /*change(ch);*/sscanf(ch,"%I64d%I64d%I64d",&x[cnt],&y[cnt],&z[cnt]),cnt++;         else if(cnt>1)        {            solve();            cnt=1;            /*memset(x,0,sizeof x);            memset(y,0,sizeof y);            memset(z,0,sizeof z);*/        }    }    if(cnt>1) solve();    return 0;}