POJ3484-Showstopper

159 篇文章 1 订阅
44 篇文章 0 订阅

Showstopper
Time Limit: 1000MS Memory Limit: 65536K
Total 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 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

Source


题意: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 long
const 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;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值