http://acm.hdu.edu.cn/showproblem.php?pid=4768

题意:n个传单分别发给编号为ai, ai + ci, ai + 2 * ci, .. , ai + k * ci的学生,其中k 是满足 ai + k * ci <= bi 的最大的k,题目保证收到传单的个数为奇数的学生最多只有一个,求这个学生的编号和收到的传单数。

方法:考虑前i个学生,sum[i]表示前i个学生收到传单的个数的奇偶性,如果sum[i]为奇数,证明那个学生一定在前i个,否则在i之后,据此可以缩小范围,自然得出二分的方法。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <stack>
#include <string>
#include <ctime>
#include <queue>
#define mem0(a) memset(a, 0, sizeof(a))
#define mem(a, b) memset(a, b, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define eps 0.0000001
#define lowbit(x) ((x) & -(x))
#define memc(a, b) memcpy(a, b, sizeof(b))
#define x_x(a) ((a) * (a))
#define LL long long
#define DB double
#define pi 3.14159265359
#define MD 10000007
#define INF (int)1e9
#define max(a, b) ((a) > (b)? (a) : (b))
using namespace std;
struct Node {
int a, b, c;
void inp() {
scanf("%d%d%d", &a, &b, &c);
}
} node[];
int n;
int sum(int p)
{
int ans = ;
for(int i = ; i <= n; i++) {
if(p < node[i].a) continue;
ans ^= (((min(node[i].b, p) - node[i].a) / node[i].c + ) & );
}
return ans;
}
int countNum(int p)
{
int ans = ;
for(int i = ; i <= n; i++) {
ans += (p >= node[i].a && p <= node[i].b && (p - node[i].a) % node[i].c == );
}
return ans;
}
int main()
{
//freopen("input.txt", "r", stdin);
while(cin>> n) {
for(int i = ; i <= n; i++) {
node[i].inp();
}
int maxID = ((LL) << ) - ;
if(sum(maxID)) {
int l = , r = maxID;
while(l < r) {
int m = ((LL)l + r) >> ;
if(sum(m)) r = m;
else l = m + ;
}
cout<< l<< " "<< countNum(l)<< endl;
}
else puts("DC Qiang is unhappy.");
}
return ;
}

[hdu4768]二分的更多相关文章

  1. hdu4768二分答案

    /* 如果发的传单是偶数,那么所有人都收到双数张. 仅考虑发了单数张传单,二分答案x,如果x左边是偶数,那么答案在右侧,如果x左边是奇数,那么答案在左侧 */ #include<iostream ...

  2. Flyer(二分 HDU4768)

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

  3. HDU4768:Flyer [ 二分的奇妙应用 好题 ]

    传送门 Flyer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  4. hdu4768 非常规的二分

    题意:       n个社团给同学发传单,同学一共有1--2^31这么多,每个社团有三个数A ,B ,C ,只有 满足 A ,A + C ,A + C + C ...A + KC <= B 的学 ...

  5. BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 8748  Solved: 3835[Submi ...

  6. BZOJ 2756: [SCOI2012]奇怪的游戏 [最大流 二分]

    2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 3352  Solved: 919[Submit][Stat ...

  7. 整体二分QAQ

    POJ 2104 K-th Number 时空隧道 题意: 给出一个序列,每次查询区间第k小 分析: 整体二分入门题? 代码: #include<algorithm> #include&l ...

  8. [bzoj2653][middle] (二分 + 主席树)

    Description 一个长度为n的序列a,设其排过序之后为b,其中位数定义为b[n/2],其中a,b从0开始标号,除法取下整. 给你一个长度为n的序列s. 回答Q个这样的询问:s的左端点在[a,b ...

  9. [LeetCode] Closest Binary Search Tree Value II 最近的二分搜索树的值之二

    Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...

随机推荐

  1. PHP函数:get_class()

    get_class()  -返回对象的类名 说明: get_class ([ object $object = NULL ] ) : string 参数: object:要测试的对象.如果在类里,此参 ...

  2. MySQL学习之正则表达式篇

    正则表达式(REGEXP) 1.简介 正则表达式是用来匹配列值的特殊字符集合,许多领域都有涉及, MySQL使用的正则表达式仅为其一个小小的子集. 2.基本字符匹配 2.1筛选包含特定字符串的信息 / ...

  3. this 关键字的用法

    用法一  this代表当前类的实例对象 class Program    {        static void Main(string[] args)        {            tr ...

  4. Python pandas库159个常用方法使用说明

    Pandas库专为数据分析而设计,它是使Python成为强大而高效的数据分析环境的重要因素. 一.Pandas数据结构 1.import pandas as pd import numpy as np ...

  5. c++<ctime>中常用函数

    先说一下c++标准库并没有提供所谓的日期类型,而是继承了c的日期类型 <cmath>里面有些常用的函数,比如计时函数clock().获取系统时间的函数time(),下面就具体的介绍一下 1 ...

  6. 为何 UNIX 时间 0, 有时显示是1970年1月1日,有时显示是1969年12月31日

    by Rachael Arnold http://www.rachaelarnold.com/dev/archive/why-is-date-returning-wrong Demystifying ...

  7. c++库 c语言接口

    //code in add.cxx #include "add.h" int sample::method() { cout<<"method is call ...

  8. IDEA设置导入主题样式皮肤,加入背景图片

    主题下载地址:http://www.riaway.com/theme.php 里面有很多主题,看个人喜好,这里我用的Monokai Sublime Text 3. 导入主题打开IDEA,找到File ...

  9. java中interrupt,interrupted和isInterrupted的区别

    文章目录 isInterrupted interrupted interrupt java中interrupt,interrupted和isInterrupted的区别 前面的文章我们讲到了调用int ...

  10. 关于SpringBoot集成myBatis时,mapper接口注入失败的问题

    问题描述: 在Spring Boot集成myBatis时,发现启动时,mapper接口一直注入失败. 现象如下: VehicleDAO就是需要的mapper对象,一个简单的接口. 已经在applica ...