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. Python - 翻译Talk Python To Me (和我聊Python) 播客

    “和我聊Python”是一个美国的聊天播客,英文名Talk Python To Me,类似于喜马拉雅的音频课程节目,只不过这个主题是编程语言Python.该节目从2015年的节目到现在,已经超过256 ...

  2. 在vue中使用ztree树插件

    插件资源及api:树官网 本事例是在vue3.0+中演示,事例是实际项目中正在用的组件所以部分打了马赛克. 1.插件准备(提前准备好插件文件) 可以直接在官网下载,搭建好脚手架后将准备好的文件放在li ...

  3. CoreDNS解析异常记录

    CoreDNS解析异常记录 异常情况:集群是用kubespray部署的4个worknode,coredns默认部署2个deployment.今天发现部署了coredns的node上的pod正常解析内部 ...

  4. vue2.x学习笔记(十八)

    接着前面的内容:https://www.cnblogs.com/yanggb/p/12629705.html. 处理边界情况 这里记录的都是和处理边界情况有关的功能,即一些需要对vue的规则做一些小调 ...

  5. [YII2] 修改默认控制器Controller以及默认方法Action

    试了好多方法都没成功,下面方法绝对能成功设置 在框架里面有源码,在/vendor/yiisoft/yii2/web/Application.php的第34行找到了: class Application ...

  6. 异常处理方式一(try-catch-finally)

    package com.yhqtv.demo01Exception; /* * 一.异常的处理,抓抛模型 * * 过程一:“抛”:程序在正常 执行的过程中,一旦出现异常,就会在异常代码处生成一个对应异 ...

  7. sqlilabs less18-22 HTTP头的注入

    less18 user-agent的注入 源码分析: check_input对name,password进行了过滤 function check_input($value) { if(!empty($ ...

  8. 2019-2020-1 20199310《Linux内核原理与分析》第八周作业

    1.问题描述 在前面的文章中,学习了在Linux系统之中如何创建一个新进程进行追踪,本文将围绕编译链接的过程和ELF可执行文件格式,对Linux内核装载和启动一个可执行程序. 2.解决过程 2.1 E ...

  9. XEP-0198:流管理

    ------------恢复内容开始------------ 原文来自:https://xmpp.org/extensions/xep-0198.html,只翻译了技术方面的内容. 摘要:这个规范定义 ...

  10. Git 提交项目命令

    git add .  //添加⽂件到待提交区 git commit -m "注释"  //创建⼀个提交 git push origin   //将修改内容提交