【题目链接】 http://poj.org/problem?id=3484

【题目大意】

  给出n个等差数列的首项末项和公差。求在数列中出现奇数次的数。题目保证至多只有一个数符合要求。

【题解】

  因为只有一个数符合要求,所以在数列中数出现次数的前缀和必定有奇偶分界线,

  所以我们二分答案,计算前缀和的奇偶性进行判断,得到该数的位置。

【代码】

  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <cstring>
  4. using namespace std;
  5. typedef long long LL;
  6. const int N=500010;
  7. const LL inf=1LL<<33;
  8. LL X[N],Y[N],Z[N];
  9. char s[60];
  10. int n;
  11. LL cal(LL x){
  12. LL ans=0,t;
  13. for(int i=1;i<=n;i++){
  14. if(x<X[i])continue;
  15. t=min(x,Y[i]);
  16. ans+=(t-X[i])/Z[i]+1;
  17. }return ans;
  18. }
  19. int main(){
  20. while(gets(s)){
  21. X[n=1]=0;
  22. sscanf(s,"%lld %lld %lld",&X[n],&Y[n],&Z[n]);
  23. if(!X[n])continue;
  24. memset(s,0,sizeof(s));
  25. while(gets(s),*s)n++,sscanf(s,"%lld %lld %lld",&X[n],&Y[n],&Z[n]),memset(s,0,sizeof(s));
  26. LL l=1,r=inf,ans=0;
  27. while(l<=r){
  28. LL mid=(l+r)>>1;
  29. if(cal(mid)&1LL)r=mid-1,ans=mid;
  30. else l=mid+1;
  31. }if(!ans)puts("no corruption");
  32. else printf("%lld %lld\n",ans,cal(ans)-cal(ans-1));
  33. }return 0;
  34. }

  

POJ 3484 Showstopper(二分答案)的更多相关文章

  1. POJ 3104 Drying(二分答案)

    题目链接:http://poj.org/problem?id=3104                                                                  ...

  2. poj 3484 Showstopper

    Showstopper Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2236   Accepted: 662 Descri ...

  3. POJ 3122 Pie 二分答案

    题意:给你n个派,每个派都是高为一的圆柱体,把它等分成f份,每份的最大体积是多少. 思路: 明显的二分答案题-- 注意π的取值- 3.14159265359 这样才能AC,,, //By Sirius ...

  4. POJ Building roads [二分答案 2SAT]

    睡觉啦 #include <iostream> #include <cstdio> #include <cstring> #include <algorith ...

  5. Poj 1743 Musical Theme(后缀数组+二分答案)

    Musical Theme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 28435 Accepted: 9604 Descri ...

  6. 字符串hash + 二分答案 - 求最长公共子串 --- poj 2774

    Long Long Message Problem's Link:http://poj.org/problem?id=2774 Mean: 求两个字符串的最长公共子串的长度. analyse: 前面在 ...

  7. POJ 1064 Cable master (二分答案)

    题目链接:http://poj.org/problem?id=1064 有n条绳子,长度分别是Li.问你要是从中切出m条长度相同的绳子,问你这m条绳子每条最长是多少. 二分答案,尤其注意精度问题.我觉 ...

  8. POJ 3662 Telephone Lines(二分答案+SPFA)

    [题目链接] http://poj.org/problem?id=3662 [题目大意] 给出点,给出两点之间连线的长度,有k次免费连线, 要求从起点连到终点,所用的费用为免费连线外的最长的长度. 求 ...

  9. POJ 3579 Median(二分答案+Two pointers)

    [题目链接] http://poj.org/problem?id=3579 [题目大意] 给出一个数列,求两两差值绝对值的中位数. [题解] 因为如果直接计算中位数的话,数量过于庞大,难以有效计算, ...

随机推荐

  1. iOS绘制view

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  2. UVA 10943 How do you add?

    设函数 f(k)(n); 则: f(1)(n)=1; f(2)(n)=f(1)(0)+f(1)(1)+f(1)(2)+...+f(1)(n); f(3)(n)=f(2)(0)+f(2)(1)+f(2) ...

  3. 03-树1. List Leaves (25)

    Given a tree, you are supposed to list all the leaves in the order of top down, and left to right. I ...

  4. [python 基础] Class 一些基本概念

    class example(object): data1 = '' date2 = "" def __init__(self, para): self._function1() d ...

  5. 分享5个主流的HTML5开发工具

    HTML5被看做是web开发者创建流行web应用的利器,增加了对视频和Canvas 2D的支持.用HTML5的优点主要在于,这个技术可以进行跨平台的使用.比如你开发了一款HTML5的游戏,你可以很轻易 ...

  6. poj 1573 Robot Motion_模拟

    又是被自己的方向搞混了 题意:走出去和遇到之前走过的就输出. #include <cstdlib> #include <iostream> #include<cstdio ...

  7. 构造函时和this指针

    通常this指针在对象构造完毕后才完全生成,而在构造函数执行过程中,对象还没有完全生成,所以this指针也是没有完全生成的,在构造函数中使用this指针会存在问题,应该尽量避免. 构造函数中可以访问对 ...

  8. WordPress中文汉字username不能注冊怎么办?

    WordPress注冊用户是不支持中文的.可是近期在项目中须要用到中文注冊. 后来想到了简单的处理办法: 打开 wp-includes/formatting.php.找到 function sanit ...

  9. 【斐波拉契+数论+同余】【ZOJ3707】Calculate Prime S

    题目大意: S[n] 表示 集合{1,2,3,4,5.......n} 不存在连续元素的子集个数 Prime S 表示S[n]与之前的所有S[i]互质; 问 找到大于第K个PrimeS 能整除X 的第 ...

  10. 小心ThreadLocal的陷阱

    ThreadLocal用在多线程时保存线程级的局部变量,当我们需要在线程内共享数据时,ThreadLocal屡试不爽,但是ThreadLocal也会有一个问题,当你使用线程池时,线程可能会被重用,所以 ...