POJ 3484

Showstopper
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 1060 Accepted: 303

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

 
由题目可知序列的前缀和必定会呈现偶偶偶偶偶奇奇奇奇奇奇,由此二分答案,然后根据前缀和判断。
 
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 
 6 using namespace std;
 7 
 8 #define maxn 500005
 9 
10 typedef long long ll;
11 
12 char str[100];
13 ll  X[maxn],Y[maxn],Z[maxn];
14 int n;
15 
16 ll check(ll mid) {
17         ll sum = 0;
18         for(int i = 1; i <= n; ++i) {
19                 if(mid < X[i]) continue;
20                 sum += (min(mid,Y[i]) - X[i]) / Z[i] + 1;
21         }
22 
23         //cout <<  "sum = " << sum << endl;
24 
25         return sum;
26 }
27 
28 void solve() {
29 
30         ll l = 0 ,r = 1LL << 33;
31 
32         while(l < r) {
33                 ll mid = (l + r) >> 1;
34                 if(check(mid) % 2 == 0) l = mid + 1;
35                 else r = mid;
36         }
37         if (l == 1LL << 33)
38             puts("no corruption");
39         else
40             printf("%I64d %I64d\n" , l , (check(l) - check(l - 1)));
41 
42 
43 }
44 
45 int main()
46 {
47     //freopen("sw.in","r",stdin);
48     n = 0;
49 
50     while(gets(str)) {
51             if(strlen(str) != 0) {
52                     ++n;
53                     sscanf(str,"%I64d %I64d %I64d",&X[n],&Y[n],&Z[n]);
54                     //printf("%I64d %I64d %I64d\n",X[n],Y[n],Z[n]);
55             }
56 
57             if(strlen(str) == 0 && n) {
58                     solve();
59                     n = 0;
60             }
61     }
62     if(n) solve();
63     return 0;
64 }
View Code

 

转载于:https://www.cnblogs.com/hyxsolitude/p/3619890.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值