Showstopper

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

题意:给出多组数据,每组间由多行空行隔开,每组数据包含多个数列,求在所有数列中出现次数为奇数次的数字。
思路:二分答案,求x以内的数字的总个数sum(x),当sum(x)%2==1 时表明 目标数字k<=x,否则k>x,以此来二分。
代码:
 //#include"bits/stdc++.h"
#include<sstream>
#include<iomanip>
#include"cstdio"
#include"map"
#include"set"
#include"cmath"
#include"queue"
#include"vector"
#include"string"
#include"cstring"
#include"time.h"
#include"iostream"
#include"stdlib.h"
#include"algorithm"
#define db double
#define ll long long
#define vec vector<ll>
#define mt vector<vec>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
//#define rep(i, x, y) for(int i=x;i<=y;i++)
#define rep(i, n) for(int i=0;i<n;i++)
const int N = 1e6 + ;
const int mod = 1e9 + ;
const int MOD = mod - ;
const int inf = 0x3f3f3f3f;
const db PI = acos(-1.0);
const db eps = 1e-;
using namespace std;
ll x[N],y[N],z[N],cnt=;
char s[N];
ll cal(ll k)
{
ll ans=;
for(int i=;i<cnt;i++){
if(k<x[i]) continue;
ans+=(min(y[i],k)-x[i])/z[i]+;//统计小于等于k的数有多少个
}
return ans;
}
ll solve()
{
ll l=-,r=(1ll<<),ans=-;
while(l<=r)
{
ll mid=(l+r)/;
if(cal(mid)%==) r=mid-,ans=mid;//若为奇数个则目标数字x<=mid
else l=mid+;//否则目标数字x>mid
}
return ans;
}
int main()
{
cnt=;
while(gets(s)!=NULL){
if(strlen(s)==)
{
if(!cnt) continue;
ll ret=solve();
if(ret==-) puts("no corruption");
else printf("%lld %lld\n",ret,cal(ret)-cal(ret-));
cnt=;
}
else
{
sscanf(s,"%lld%lld%lld",&x[cnt],&y[cnt],&z[cnt]);//必须用sscanf?
cnt++;
}
}
if(cnt)
{
ll ret=solve();
if(ret==-) puts("no corruption");
else printf("%lld %lld\n",ret,cal(ret)-cal(ret-));
}
return ;
}

最新文章

  1. 关于JavaScript中的delete操作
  2. 适配iOS10的哪些事 ---- 学习笔记八
  3. MVC - 19.Log4net
  4. 【JavaScript学习笔记】hello world
  5. Zookeeper实现分布式选举算法
  6. 转载:Restore SQL Server database and overwrite existing database
  7. 对.Net WebSocket 和Socket的原理的思考
  8. mvc的真实含义
  9. 简单的新闻客户端APP开发(DCloud+thinkphp+scrapy)
  10. Udacity-Artificial Intelligence for Robotics 课程笔记
  11. servlet三种实现方式之二继承GenericServlet开发
  12. Android 之xml解析
  13. Android studio导出配置
  14. Prometheus使用入门
  15. python数据分析算法(决策树2)CART算法
  16. ZYNQ DMA驱动及测试分析
  17. 【AtCoder】KEYENCE Programming Contest 2019
  18. BZOJ.1758.[WC2010]重建计划(分数规划 点分治 单调队列/长链剖分 线段树)
  19. PC端和移动端在前端开发上的一些区别,前端里移动端到底比pc端多哪些知识
  20. python之文件操作的几种模式总结

热门文章

  1. Redis的原子自增性
  2. BZOJ3261: 最大异或和(可持久化trie树)
  3. sudoers文件解析
  4. 笨办法学Python(三十七)
  5. 2017.10.28 QB模拟赛 —— 上午
  6. MySQL入门很简单: 14MySQL日志
  7. java文件
  8. .net core 2.0 WIndows IIS下发布(WIN 10环境)
  9. android+nutz后台如何上传和下载图片
  10. 【BZOJ5212】[ZJOI2018] 历史(LCT大黑题)