Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 1150 | Accepted: 327 |
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
题意:表示没看懂。
思路:根据每次给你的三个数,让所有遍历到的数都+1,然后找到这个数遍历到的次数是奇数次的数,并输出它的遍历次数。题目中最多只有一个数是这样的,所以前面所有数的遍历次数和必是偶数,后面的必是奇数。二分找到这个数。另外就是丧病的读入。
AC代码如下:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
char str[60];
long long x[500010],y[500010],z[500010],n;
long long solve(long long mid)
{ long long i,j,ans=0,k;
for(i=1;i<=n;i++)
if(mid>=x[i])
{ k=min(y[i],mid);
ans+=(k-x[i])/z[i]+1;
}
return ans;
}
int main()
{ long long i,j,k,l,r,mid;
while(gets(str))
{ n = 1;
x[n] = 0;
sscanf(str,"%I64d %I64d %I64d",&x[n],&y[n],&z[n]);
if (!x[n])
continue;
memset(str,0,sizeof(str));
while(gets(str),*str)
{ n++;
sscanf(str,"%I64d %I64d %I64d",&x[n],&y[n],&z[n]);
memset(str,0,sizeof(str));
}
l=1;r=100000000000;
while(l<=r)
{ mid=(l+r)/2;
if(solve(mid)%2==1)
r=mid-1;
else
l=mid+1;
}
if(l >= 100000000000)
printf("no corruption\n");
else
{ k=solve(l)-solve(l-1);
printf("%I64d %I64d\n",l,k);
}
}
}