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 ;
}

POJ 3484 二分的更多相关文章

  1. POJ - 2018 二分+单调子段和

    依然是学习分析方法的一道题 求一个长度为n的序列中的一个平均值最大且长度不小于L的子段,输出最大平均值 最值问题可二分,从而转变为判定性问题:是否存在长度大于等于L且平均值大于等于mid的字段和 每个 ...

  2. POJ 3484 Showstopper(二分答案)

    [题目链接] http://poj.org/problem?id=3484 [题目大意] 给出n个等差数列的首项末项和公差.求在数列中出现奇数次的数.题目保证至多只有一个数符合要求. [题解] 因为只 ...

  3. poj 3621 二分+spfa判负环

    http://poj.org/problem?id=3621 求一个环的{点权和}除以{边权和},使得那个环在所有环中{点权和}除以{边权和}最大. 0/1整数划分问题 令在一个环里,点权为v[i], ...

  4. POJ 3061 (二分+前缀和or尺取法)

    题目链接: http://poj.org/problem?id=3061 题目大意:找到最短的序列长度,使得序列元素和大于S. 解题思路: 两种思路. 一种是二分+前缀和.复杂度O(nlogn).有点 ...

  5. POJ 2456 (二分)

    题目链接: http://poj.org/problem?id=2456 题目大意:n个房子,m头牛,房子有一个横坐标,问将m头牛塞进房子,每两头牛之间的最大间隔是多少. 解题思路: 不难看出应该二分 ...

  6. POJ 1064 (二分)

    题目链接: http://poj.org/problem?id=1064 题目大意:一堆棍子可以截取,问要求最后给出K根等长棍子,求每根棍子的最大长度.保留2位小数.如果小于0.01,则输出0.00 ...

  7. poj 3228(二分+最大流)

    题目链接:http://poj.org/problem?id=3228 思路:增设一个超级源点和一个超级汇点,源点与每一个gold相连,容量为gold数量,汇点与仓库相连,容量为仓库的容量,然后就是二 ...

  8. poj 3685 二分

    Matrix Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 7415   Accepted: 2197 Descriptio ...

  9. POJ 3579 二分

    Median Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7687   Accepted: 2637 Descriptio ...

随机推荐

  1. FastDFS 注意事项

    1.nginx集成FastDFS模块时,配置文件问题 检测到nginx日志:  /home/soft/fastdfs-nginx-module/src/common.c, line: 155, loa ...

  2. iOS - 通过view查找所在(viewController)

    - (UIViewController *)findViewController:(UIView *)sourceView { id target=sourceView; while (target) ...

  3. [SVN]TortoiseSVN工具培训5─常见问题解决

    1.文件提交时状态异常 产生原因:操作不当 解决方法:使用SVN的clean up命令 2.权限不足 产生原因:当前用户权限不足 解决方法:找配置管理员申请权限 3.网络故障 产生原因:无法访问到配置 ...

  4. jquery中对于ul>li列表分页。学习记录

    这个是很简单的一种分页,只能对列表进行分页.为了开发有可能需要用到记录下来 Html代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 T ...

  5. 在微信小程序里自动获得当前手机所在的经纬度并转换成地址

    效果:我在手机上打开微信小程序,自动显示出我当前所在的地理位置: 具体步骤: 1. 使用微信jssdk提供的getLocation API拿到经纬度: 2. 调用高德地图的api使用经纬度去换取地址的 ...

  6. Linux同步目录 保留文件修改时间和权限 rsync

    scp copy文件夹的时候,会强行覆盖文件,导致增量同步的时候不方便,而rsync则能很好解决这个问题. rsync -avz ubuntu@192.168.1.208:/home/ubuntu/m ...

  7. dotNetFx40_Client_x86_x64和dotNetFx40_Full_x86_x64这两个有什么区别?两个都要安装还是安装其中一个?

    这个是NET Framework 4.0的安装文件它是支持生成和运行下一代应用程序和 XML Web Services 的内部 Windows 组件,很多基于此架构的程序需要它的支持才能够运行.简单的 ...

  8. 2017.10.12 Java的计数器的开发

    //我们用一个合成的applet/application来简单显示出一个计数器的结果/** * Created by qichunlin on 2017/10/12. */ /*简单的计数器*/ im ...

  9. Ubuntu搜狗输入法无法输入中文等问题

    Linux版本的搜狗输入法经常崩溃,无法输入中文,今天作下记录,环境:Ubuntu14.04 64位 1.安装和卸载 Linux搜狗是基于框架fcitx的,先得安装框架Ubunt安装搜狗方法 也可以直 ...

  10. java的四个元注解 @Retention @Target @Document @Inherited

    1.  @Retention  :注解的保留位置 @Retention(RetentionPolicy.SOURCE)  //注解仅存在于源码中,在class字节码文件中不包含 @Retention( ...