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]区间内。
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MAXN = ;
const LL INF = 0x7fffffffffffffff;
struct Node{
LL a, b, c;
}soc[MAXN];
int n;
bool test(LL x)
{
LL s = ;
for(int i = ; i < n; i++)
{
LL l = min(x, soc[i].b);
if(l >= soc[i].a)
{
s += ((l - soc[i].a) / soc[i].c + );
}
}
return s & ;
}
int main()
{
while(scanf("%d", &n) != EOF)
{
LL mn = INF, mx = ;
for(int i = ; i < n; i++)
{
scanf("%I64d %I64d %I64d", &soc[i].a, &soc[i].b, &soc[i].c);
mn = min(mn, soc[i].a);
mx = max(mx, soc[i].b);
}
LL left = mn, right = mx;
if(!test(right))
{
printf("DC Qiang is unhappy.\n");
continue;
}
while(right > left)
{
LL mid = (left + right) >> ;
if(test(mid))
{
right = mid;
}
else
{
left = mid + ;
}
}
LL res = ;
for(int i = ; i < n; i++)
{
if(right > soc[i].b || right < soc[i].a) continue;
if((right - soc[i].a) % soc[i].c == )
{
res++;
}
}
printf("%I64d %I64d\n", right, res);
}
return ;
}

异或运算也能过。

#include <cstdio>
using namespace std;
typedef long long LL;
const int MAXN = ;
struct Node{
LL a, b, c;
}soc[MAXN];
int n;
int main()
{
while(scanf("%d", &n) != EOF)
{
for(int i = ; i < n; i++)
{
scanf("%I64d %I64d %I64d", &soc[i].a, &soc[i].b, &soc[i].c);
}
LL x = ;
for(int i = ; i < n; i++)
{
for(LL l = soc[i].a; l <= soc[i].b; l += soc[i].c)
{
x ^= l;
}
}
if(x != )
{
LL res = ;
for(int i = ; i < n; i++)
{
if(x > soc[i].b || x < soc[i].a) continue;
if((x - soc[i].a) % soc[i].c == )
{
res++;
}
}
printf("%I64d %I64d\n", x, res);
}
else
{
printf("DC Qiang is unhappy.\n");
}
}
return ;
}

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. volatile笔记

    总结自:https://www.cnblogs.com/dolphin0520/p/3920373.html 了解volatile之前得明白什么是原子性.可见性.有序性及指令重排序,详见:https: ...

  2. 20145239《网络对抗》- 逆向及Bof基础实践

    1 逆向及Bof基础实践说明 1.1 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件.该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用户输入的字符串.该程序同 ...

  3. INSPIRED启示录 读书笔记 - 第2章 产品管理与产品营销

    两者不是一回事 1.产品经理的工作是从细节上定义开发团队开发什么产品 2.市场营销的职责是对外宣传产品 产品公司常常会陷入的三种误区 1.由市场营销人员定义产品:由产品营销经理或所谓的产品经理负责收集 ...

  4. 利用CXF框架开发webservice

    开发服务端代码 1. web.xml文件中添加cxf的servlet 2. 定义接口 @WebService(targetNamespace="http://UserInfo.ws.com& ...

  5. C语言下文件目录查看

    C语言下文件目录遍历通常会用到下面这些函数 _access()        /* 判断文件或文件夹路径是否合法 */ _chdir() /* 切换当前工作目录 */ _findfirst()   / ...

  6. 免配置环境变量使用Tomcat+设置项目主页路径为http://localhost:8080+修改tomcat端口号

    一.免配置jdk JAVA_HOME和tomcat  CATALINA_HOME环境变量使用tomcat 众说周知,使用tomcat需要有java环境,一般情况下需要配置jdk和tomcat的路径到w ...

  7. iOS学习笔记之正则表达式

    前言 基本上每个 App 都有登录注册功能,在登录注册时需要验证用户所输入的内容是否符合规定:有时要在字符串中查找并截取符合要求的字符串,这时就需要用到正则表达式.正则表达式看起来晦涩难懂,没有什么规 ...

  8. R语言可视化

    R语言基础(一) 可视化基础   ##数据获取 x1=round(runif(100,min=80,max=100)) x2=round(rnorm(100,mean=80, sd=7)) x3=ro ...

  9. review06

    使用关键字interface来定义一个接口.接口的定义和类定义很相似,分为接口声明和接口体. 接口体中包含常量的声明(没有变量)和抽象方法两部分.接口中只有抽象方法,没有普通方法.而且接口体中所有的常 ...

  10. QBXT Day 4 数学,数论

    今天讲一讲数论吧(虽然清明讲过了) 进制转换 我们来看10这个数怎么转换成k进制 因为10=2^3+2^1,所以10就是1010 三进制也同理10=3^2+3^0,所以就是101 我们对于一个10进制 ...