Flyer

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2795    Accepted Submission(s): 1051

Problem Description
The new semester begins! Different kinds of student societies are all trying to advertise themselves, by giving flyers to the students for introducing the society. However, due to the fund shortage, the flyers of a society can only be distributed to a part of the students. There are too many, too many students in our university, labeled from 1 to 2^32. And there are totally N student societies, where the i-th society will deliver flyers to the students with label A_i, A_i+C_i,A_i+2*C_i,…A_i+k*C_i (A_i+k*C_i<=B_i, A_i+(k+1)*C_i>B_i). We call a student "unlucky" if he/she gets odd pieces of flyers. Unfortunately, not everyone is lucky. Yet, no worries; there is at most one student who is unlucky. Could you help us find out who the unfortunate dude (if any) is? So that we can comfort him by treating him to a big meal!
 
Input
There are multiple test cases. For each test case, the first line contains a number N (0 < N <= 20000) indicating the number of societies. Then for each of the following N lines, there are three non-negative integers A_i, B_i, C_i (smaller than 2^31, A_i <= B_i) as stated above. Your program should proceed to the end of the file.
 
Output
For each test case, if there is no unlucky student, print "DC Qiang is unhappy." (excluding the quotation mark), in a single line. Otherwise print two integers, i.e., the label of the unlucky student and the number of flyers he/she gets, in a single line.
 
Sample Input
2
1 10 1
2 10 1
4
5 20 7
6 14 3
5 9 1
7 21 12
 
Sample Output
1 1
8 1
 
思路:二分枚举区间(l,r],mid=(l+r)/2。若(l,mid]出现的数字次数之和为奇数,由奇数+偶数为奇数可得,答案必在(l,mid]内。否则,在(mid,r]区间内。
  1. #include <cstdio>
  2. #include <algorithm>
  3. using namespace std;
  4. typedef long long LL;
  5. const int MAXN = ;
  6. const LL INF = 0x7fffffffffffffff;
  7. struct Node{
  8. LL a, b, c;
  9. }soc[MAXN];
  10. int n;
  11. bool test(LL x)
  12. {
  13. LL s = ;
  14. for(int i = ; i < n; i++)
  15. {
  16. LL l = min(x, soc[i].b);
  17. if(l >= soc[i].a)
  18. {
  19. s += ((l - soc[i].a) / soc[i].c + );
  20. }
  21. }
  22. return s & ;
  23. }
  24. int main()
  25. {
  26. while(scanf("%d", &n) != EOF)
  27. {
  28. LL mn = INF, mx = ;
  29. for(int i = ; i < n; i++)
  30. {
  31. scanf("%I64d %I64d %I64d", &soc[i].a, &soc[i].b, &soc[i].c);
  32. mn = min(mn, soc[i].a);
  33. mx = max(mx, soc[i].b);
  34. }
  35. LL left = mn, right = mx;
  36. if(!test(right))
  37. {
  38. printf("DC Qiang is unhappy.\n");
  39. continue;
  40. }
  41. while(right > left)
  42. {
  43. LL mid = (left + right) >> ;
  44. if(test(mid))
  45. {
  46. right = mid;
  47. }
  48. else
  49. {
  50. left = mid + ;
  51. }
  52. }
  53. LL res = ;
  54. for(int i = ; i < n; i++)
  55. {
  56. if(right > soc[i].b || right < soc[i].a) continue;
  57. if((right - soc[i].a) % soc[i].c == )
  58. {
  59. res++;
  60. }
  61. }
  62. printf("%I64d %I64d\n", right, res);
  63. }
  64. return ;
  65. }

异或运算也能过。

  1. #include <cstdio>
  2. using namespace std;
  3. typedef long long LL;
  4. const int MAXN = ;
  5. struct Node{
  6. LL a, b, c;
  7. }soc[MAXN];
  8. int n;
  9. int main()
  10. {
  11. while(scanf("%d", &n) != EOF)
  12. {
  13. for(int i = ; i < n; i++)
  14. {
  15. scanf("%I64d %I64d %I64d", &soc[i].a, &soc[i].b, &soc[i].c);
  16. }
  17. LL x = ;
  18. for(int i = ; i < n; i++)
  19. {
  20. for(LL l = soc[i].a; l <= soc[i].b; l += soc[i].c)
  21. {
  22. x ^= l;
  23. }
  24. }
  25. if(x != )
  26. {
  27. LL res = ;
  28. for(int i = ; i < n; i++)
  29. {
  30. if(x > soc[i].b || x < soc[i].a) continue;
  31. if((x - soc[i].a) % soc[i].c == )
  32. {
  33. res++;
  34. }
  35. }
  36. printf("%I64d %I64d\n", x, res);
  37. }
  38. else
  39. {
  40. printf("DC Qiang is unhappy.\n");
  41. }
  42. }
  43. return ;
  44. }

HDOJ4768(二分区间)的更多相关文章

  1. HDU 4768 (二分区间---涨姿势)

    题意:告诉n组A,B,C,按照A + k * C生成等差数列,问这n组数列中哪个数字出现了奇数次以及出现了几次,题目保证最多只会出现一个这种数字. 分析:读完题并没有思路,后来知道是二分区间,枚举是哪 ...

  2. HDU 5875 st+二分区间

    题目大意:给你n个数,q次询问,每次询问区间[l, r],问a[i]%a[i + 1] % a[i + 2]...%a[j](j <= r)的值 思路:st预处理维护,再二分区间,复杂度n*(l ...

  3. 【BZOJ】1044: [HAOI2008]木棍分割 二分+区间DP

    链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1044 Description 有n根木棍, 第i根木棍的长度为Li,n根木棍依次连结了一起, ...

  4. 【NOIP2013模拟】终极武器(经典分析+二分区间)

    No.2. [NOIP2013模拟]终极武器 题意: 给定你一些区间,然后让你找出\(1\sim 9\)中的等价类数字. 也就是说在任何一个区间里的任何一个数,把其中后\(k\)位中的某一位换成等价类 ...

  5. HDU - 4614 Vases and Flowers(二分+区间修改)

    https://cn.vjudge.net/problem/HDU-4614 题意 n个花瓶,m个操作,花瓶里面有的有花,有的是空的.1操作是从a开始往右放b朵花,花瓶有了的不放,跳过,直到a右边都放 ...

  6. HDU 5289 Assignment (二分+区间最值)

    [题目链接]click here~~ [题目大意]: 给出一个数列,问当中存在多少连续子序列,子序列的最大值-最小值<k [思路]:枚举数列左端点.然后二分枚举右端点,用ST算法求区间最值.(或 ...

  7. vijos1740 聪明的质监员 (二分、区间求和)

    http://www.rqnoj.cn/problem/657 https://www.vijos.org/p/1740 P1740聪明的质检员 请登录后递交 标签:NOIP提高组2011[显示标签] ...

  8. Todd's Matlab讲义第5讲:二分法和找根

    二分法和if ... else ... end 语句 先回顾一下二分法.要求方程\(f(x)=0\)的根.假设\(c = f(a) < 0\)和\(d = f(b) > 0\),如果\(f ...

  9. Codeforces Beta Round #75 (Div. 1 Only) B. Queue 线段树+二分

    B. Queue Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/problem/91/B Descrip ...

随机推荐

  1. maven junit.framework不存在问题解决

    问题 在使用maven进行一个工程的编译,已加入junit包的依赖,编译的时候却总是报“junit.framework不存在”错误. pom.xml中junit包加入如下: <dependenc ...

  2. Centos6.5安装glusterfs3.6.2

    硬件环境Centos6.5  glusterfs3.6.2 先安装必要的包 yum install flex bison 2. 下载glusterfs3.6.2 wget http://downloa ...

  3. 【P2016】战略游戏(贪心||树状DP)

    这个题真是...看了一会之后,发现有一丝丝的熟悉,再仔细看了看,R,这不是那个将军令么...然后果断调出来那个题,还真是,而且貌似还是简化版的...于是就直接改了改建树和输入输出直接交了..阿勒,就2 ...

  4. mybatis 中if标签判断boolean 的写法。

    mybatis 的if 比较标签在比较数值时可以这样写: <if test="value=0"> </if> 在比较字符串时可以这么写: <if te ...

  5. 一个简单的Javascript闭包示例

    //=====用闭包实现函数的Curry化===== //数字求和函数的函数生成器 function addGenerator( num ){ //返回一个简单的匿名函数,求两个数的和,其中第一个数字 ...

  6. Mfc 建立窗口线程

    之前一直都是在学习C,但是没用MFC写过东西.所以这个算是MFC的一个处女作把. 今天硬着头皮写了个爆破工具,但是界面(edit控制)在显示的时候一下就被卡住了. 于是到处问人,后来有个不错的朋友帮我 ...

  7. VC SOCKET 压缩通信学习

    Server................// Server.cpp : Defines the entry point for the console application. // #inclu ...

  8. 编写TreeSet类的实现程序,其中相关的迭代器使用二叉查找树

    package com.test.tree; import java.util.Iterator; /** * 编写TreeSet类的实现程序,其中相关的迭代器使用二叉查找树. * 在每个节点上添加一 ...

  9. 导入别人struts2项目可能要做的改变

    然后: 接着 再接着 最后

  10. 啥是ETL、ELT

    ETL就是Extract.Transfrom.Load即抽取.转换.加载三个英文单词首字母的集合.抽取:就是从源系统抽取需要的数据,这些源系统可以是同构也可以是异构的:比如源系统可能是Excel电子表 ...