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. 1 10 1
  2. 2 10 1
  3.  
  4. 1 10 1
  5. 1 10 1
  6.  
  7. 1 10 1
  8. 4 4 1
  9. 1 5 1
  10. 6 10 1

Sample Output

  1. 1 1
  2. no corruption
  3. 4 3

Source

题意:给出多组数据,每组间由多行空行隔开,每组数据包含多个数列,求在所有数列中出现次数为奇数次的数字。
思路:二分答案,求x以内的数字的总个数sum(x),当sum(x)%2==1 时表明 目标数字k<=x,否则k>x,以此来二分。
代码:
  1. //#include"bits/stdc++.h"
  2. #include<sstream>
  3. #include<iomanip>
  4. #include"cstdio"
  5. #include"map"
  6. #include"set"
  7. #include"cmath"
  8. #include"queue"
  9. #include"vector"
  10. #include"string"
  11. #include"cstring"
  12. #include"time.h"
  13. #include"iostream"
  14. #include"stdlib.h"
  15. #include"algorithm"
  16. #define db double
  17. #define ll long long
  18. #define vec vector<ll>
  19. #define mt vector<vec>
  20. #define ci(x) scanf("%d",&x)
  21. #define cd(x) scanf("%lf",&x)
  22. #define cl(x) scanf("%lld",&x)
  23. #define pi(x) printf("%d\n",x)
  24. #define pd(x) printf("%f\n",x)
  25. #define pl(x) printf("%lld\n",x)
  26. //#define rep(i, x, y) for(int i=x;i<=y;i++)
  27. #define rep(i, n) for(int i=0;i<n;i++)
  28. const int N = 1e6 + ;
  29. const int mod = 1e9 + ;
  30. const int MOD = mod - ;
  31. const int inf = 0x3f3f3f3f;
  32. const db PI = acos(-1.0);
  33. const db eps = 1e-;
  34. using namespace std;
  35. ll x[N],y[N],z[N],cnt=;
  36. char s[N];
  37. ll cal(ll k)
  38. {
  39. ll ans=;
  40. for(int i=;i<cnt;i++){
  41. if(k<x[i]) continue;
  42. ans+=(min(y[i],k)-x[i])/z[i]+;//统计小于等于k的数有多少个
  43. }
  44. return ans;
  45. }
  46. ll solve()
  47. {
  48. ll l=-,r=(1ll<<),ans=-;
  49. while(l<=r)
  50. {
  51. ll mid=(l+r)/;
  52. if(cal(mid)%==) r=mid-,ans=mid;//若为奇数个则目标数字x<=mid
  53. else l=mid+;//否则目标数字x>mid
  54. }
  55. return ans;
  56. }
  57. int main()
  58. {
  59. cnt=;
  60. while(gets(s)!=NULL){
  61. if(strlen(s)==)
  62. {
  63. if(!cnt) continue;
  64. ll ret=solve();
  65. if(ret==-) puts("no corruption");
  66. else printf("%lld %lld\n",ret,cal(ret)-cal(ret-));
  67. cnt=;
  68. }
  69. else
  70. {
  71. sscanf(s,"%lld%lld%lld",&x[cnt],&y[cnt],&z[cnt]);//必须用sscanf?
  72. cnt++;
  73. }
  74. }
  75. if(cnt)
  76. {
  77. ll ret=solve();
  78. if(ret==-) puts("no corruption");
  79. else printf("%lld %lld\n",ret,cal(ret)-cal(ret-));
  80. }
  81. return ;
  82. }

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. ListView中CheckBox错乱解决

    思路: ListView在复用的时候会出现很多问题,CheckBox状态会出现错乱,解决思路: 1.使用Map集合的键值对的形式来存放position位置上CheckBox的状态 2.监听CheckB ...

  2. 学习html5 app项目开发

    这周因为部门接了个小的html5 app case,所以从事android开发的我就接下了这个项目.与其说是项目需要,其实更大部分是我自己想要做html5 app,因为我对这个全新的平台已经好奇很久了 ...

  3. formvalidator插件

    一.引用jquery 二.引用formValidator.js //================================================================== ...

  4. ssh代理登录内网服务器

    服务器 192.168.48.81 # client 192.168.48.82 # bastion 192.168.48.83 # private password方式 192.168.48.81 ...

  5. Mybatis:Reader entry: ���� 4

    Mybatis:Reader entry: ���� 4 现象:   产生原因:mybatis-config.xml里面配置了包的别名引发的   处理过程:注释掉 结果:就没有乱码了

  6. vos2009如何监听客户行业是否正规

    在对接被叫改写规则中将改写规则由原来0:9150 改为0:9150+自己手机号,这样客户打出话全转接到自己手机上,可以接听客户销售行业:

  7. Linux教程之:Nginx [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)

    Nginx [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use) 使用命令关闭占用80端口的程序 sudo fuser - ...

  8. 5 - 文件I/O操作

    读写文件是最常见的IO操作.Python内置了读写文件的函数,用法和C是兼容的 写文件 #打开data.txt,创建一个实例f f = open('data.txt','w') #向文件中写内容 f. ...

  9. 《转化:提升网站流量和转化率的技巧》:结合市场营销六阶段理论,以SEM为手段,提高网站转化率的技巧

    全书结合市场营销的六阶段理论,讲述各阶段的营销方面的要点和网站上吸引访客的技巧.举了一些例子,列举了一些工具.当然都是美国市场中的例子和网站优化的工具. 没有太多的新意.没看过相关图书的可以看看.

  10. Eclipse Python插件 PyDev

    PyDev for Eclipse 是一个功能强大且易用的 Eclipse Python IDE 插件.本文将向读者介绍 PyDev 开源项目及其安装配置方法,并在此基础上详细介绍如何利用 PyDev ...