Flyer

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

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
 
Source
 
Recommend
liuyiding
 

因为最多一个奇数的,所以总数是奇数的。

二分区间就可以了。

比赛时候二分的 l,r都是int存的,导致算mid = (l+r)/2的时候溢出了,TAT

这样TLE了好久,我艹。。。。。

水题一发

  1. /* ***********************************************
  2. Author :kuangbin
  3. Created Time :2013/9/28 星期六 13:00:24
  4. File Name :2013长春网络赛\1010.cpp
  5. ************************************************ */
  6.  
  7. #pragma comment(linker, "/STACK:1024000000,1024000000")
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <iostream>
  11. #include <algorithm>
  12. #include <vector>
  13. #include <queue>
  14. #include <set>
  15. #include <map>
  16. #include <string>
  17. #include <math.h>
  18. #include <stdlib.h>
  19. #include <time.h>
  20. using namespace std;
  21.  
  22. const int MAXN = ;
  23. long long A[MAXN];
  24. long long B[MAXN];
  25. long long C[MAXN];
  26. int n;
  27. inline long long calc(long long start,long long add,long long end)
  28. {
  29. return (end-start+ + add-)/add;
  30. }
  31. inline bool check(long long l,long long r)
  32. {
  33. long long sum = ;
  34. for(int i = ;i < n;i++)
  35. {
  36. long long end = min(B[i],r);
  37. if(end < A[i])continue;
  38. if(l >end)continue;
  39. long long s1;
  40. s1 = calc(A[i],C[i],end);
  41. if(l <= A[i])sum += s1;
  42. else sum += s1 - calc(A[i],C[i],l-);
  43.  
  44. }
  45. if(sum % == )return false;
  46. return true;
  47. }
  48. long long ttt(long long l,long long r)
  49. {
  50. long long sum = ;
  51. for(int i = ;i < n;i++)
  52. {
  53. long long end = min(B[i],r);
  54. if(end < A[i])continue;
  55. if(l > end)continue;
  56. long long s1,s2;
  57. s1 = calc(A[i],C[i],end);
  58. if(l <= A[i])sum += s1;
  59. else sum += s1 - calc(A[i],C[i],l-);
  60.  
  61. }
  62. return sum;
  63. }
  64. int main()
  65. {
  66. //freopen("in.txt","r",stdin);
  67. //freopen("out.txt","w",stdout);
  68. while(scanf("%d",&n) == && n)
  69. {
  70. long long l = 100000000000LL, r = ;
  71. for(int i = ;i < n;i++)
  72. {
  73. scanf("%I64d%I64d%I64d",&A[i],&B[i],&C[i]);
  74. l = min(l,A[i]);
  75. r = max(r,B[i]);
  76. }
  77. if(check(l,r) == false)
  78. {
  79. printf("DC Qiang is unhappy.\n");
  80. continue;
  81. }
  82. while(l < r)
  83. {
  84. long long mid = (l+r)/;
  85. if(check(l,mid))
  86. {
  87. r = mid;
  88. }
  89. else l = mid+;
  90. }
  91. printf("%d %d\n",(int)l,(int)ttt(l,l));
  92. }
  93. return ;
  94. }

HDU 4768 Flyer (2013长春网络赛1010题,二分)的更多相关文章

  1. HDU 4762 Cut the Cake (2013长春网络赛1004题,公式题)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  2. HDU 4759 Poker Shuffle(2013长春网络赛1001题)

    Poker Shuffle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  3. HDU 4764 Stone (2013长春网络赛,水博弈)

    Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  4. HDU 4747 Mex (2013杭州网络赛1010题,线段树)

    Mex Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submis ...

  5. hdu 5441 (2015长春网络赛E题 带权并查集 )

    n个结点,m条边,权值是 从u到v所花的时间 ,每次询问会给一个时间,权值比 询问值小的边就可以走 从u到v 和从v到u算不同的两次 输出有多少种不同的走法(大概是这个意思吧)先把边的权值 从小到大排 ...

  6. hdu 4813(2013长春现场赛A题)

    把一个字符串分成N个字符串 每个字符串长度为m Sample Input12 5 // n mklmbbileay Sample Outputklmbbileay # include <iost ...

  7. HDU 4763 Theme Section (2013长春网络赛1005,KMP)

    Theme Section Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  8. HDU 4816 Bathysphere (2013长春现场赛D题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 2013长春区域赛的D题. 很简单的几何题,就是给了一条折线. 然后一个矩形窗去截取一部分,求最 ...

  9. HDU 4751 Divide Groups (2013南京网络赛1004题,判断二分图)

    Divide Groups Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

随机推荐

  1. Myeclipse/STS 首次在本地部署配置一个Spring MVC 项目 (十二)

    1. 在本地新创建一个文件夹 ,做为项目工作空间; 2. 用 Myeclipse 或 STS 进入该文件夹,该文件夹就成为项目的工作空间: 3. 就要进 窗口-首选项,配置: 环境默认编码: 1> ...

  2. (转)js函数前加分号和感叹号是什么意思?有什么用?

    转载地址:https://www.cnblogs.com/mq0036/p/4605255.html 一般看JQuery插件里的写法是这样的 (function($) { //... })(jQuer ...

  3. js和css实现内容超过边框,就自动省略,自动添加title

    在项目汇总,我们有这样的需求,如果内容多了,就自动省略,自动添加title 这个需要判断判断俩个值,一个是width(),一个是scrollWidth, 在div中,如果内容没有超过边框,这俩个值是一 ...

  4. HDU 2512 一卡通大冒险(第二类斯特林数+贝尔数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2512 题目大意:因为长期钻研算法, 无暇顾及个人问题,BUAA ACM/ICPC 训练小组的帅哥们大部 ...

  5. SRILM Ngram 折扣平滑算法

    关于n-gram 语言模型,大部分在这篇博客里 记过了,   SRILM 语言模型格式解读 , 其实看完了,ngram的大概用法都比较清楚了, 但是关于平滑算法,一直很模糊,就晓得一个"劫富 ...

  6. 【LOJ】#2178. 「BJOI2017」机动训练

    题解 遇见平方和就转有序对呗 dp类似从很多点出发每次走一步的转移方式 然后我too naive的,枚举路径长度来决定更新次数,愉快TLE 改成记搜就过了 代码 #include <bits/s ...

  7. homestead实现外部局域网络其他主机的访问

    转载自:https://blog.csdn.net/u013659696/article/details/78455362 homestead 2.0 MAC环境 修改Homestead目录下的Vag ...

  8. CSS------如何让大小不一样的div顶部对齐

    方法一:(推荐) <div style="float:left;margin-right:20px"> <img src="/source/s_1701 ...

  9. spark优化:spark.serializer修改序列化方式

    进行节点的数据传递,或者保存数据时都会进行序列化.spark默认的是org.apache.spark.serializer.JavaSerializer.而我们要修改成org.apache.spark ...

  10. 000 关于IDEA的基本环境配置以及快速使用(git拉载程序,Jdk安装,tomcat部署,应用程序打包运行)

    刚开始工作的时候,不熟悉,所以整理过这个文档. 一:导入git程序 1.准备 git链接 IDEA软件,最好是终极版 2.第一步选择从版本控制上选择git 3.拷贝源于目标地址 4.这时候根据引导进行 ...