题意转化:有一些区间,要求选一些连续的区间。两两区间间隔的和要求小于H。要求区间的长度和尽可能长。

二分区间长度的和,check一下就行

 #include <bits/stdc++.h>

 using namespace std;

 struct node {
int l,r;
}; node a[]; int n,h; bool check(int mid) { int ans = a[].r - a[].l;
if(ans >= mid) {
return true;
}
int cha = ;
int ll = ;
for(int i = ; i <= n; i++) {
//cout<<ans<<endl;
ans += a[i].r - a[i].l;
cha += a[i].l - a[i - ].r; while(cha >= h) {
cha -= a[ll + ].l - a[ll].r;
ans -= a[ll].r - a[ll].l;
ll++;
}
//cout<<mid<<' '<<cha<<endl;
if(ans >= mid) {
return true;
}
} return false;
}
int main() { scanf("%d %d",&n,&h); for(int i = ; i <= n; i++) {
scanf("%d %d",&a[i].l,&a[i].r);
} int l = ;
int r = ;
int mid; while(r - l > ) {
mid = l + r >> ;
if(check(mid)) {
l = mid;
}
else {
r = mid;
}
} printf("%d",l + h); return ;
}

codeforces 1041 d 二分的更多相关文章

  1. codeforces 1041 e 构造

    Codeforces 1041 E 构造题. 给出一种操作,对于一棵树,去掉它的一条边.那么这颗树被分成两个部分,两个部分的分别的最大值就是这次操作的答案. 现在给出一棵树所有操作的结果,问能不能构造 ...

  2. codeforces 1165F1/F2 二分好题

    Codeforces 1165F1/F2 二分好题 传送门:https://codeforces.com/contest/1165/problem/F2 题意: 有n种物品,你对于第i个物品,你需要买 ...

  3. codeforces 732D(二分)

    题目链接:http://codeforces.com/contest/732/problem/D 题意:有m门需要过的课程,n天的时间可以选择复习.考试(如果的d[i]为0则只能复习),一门课至少要复 ...

  4. CodeForces 359D (数论+二分+ST算法)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=47319 题目大意:给定一个序列,要求确定一个子序列,①使得该子序 ...

  5. CodeForces 163B Lemmings 二分

    Lemmings 题目连接: http://codeforces.com/contest/163/problem/B Descriptionww.co As you know, lemmings li ...

  6. CodeForces - 589A(二分+贪心)

    题目链接:http://codeforces.com/problemset/problem/589/F 题目大意:一位美食家进入宴会厅,厨师为客人提供了n道菜.美食家知道时间表:每个菜肴都将供应. 对 ...

  7. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

  8. CodeForces - 1059D(二分+误差)

    链接:CodeForces - 1059D 题意:给出笛卡尔坐标系上 n 个点,求与 x 轴相切且覆盖了所有给出点的圆的最小半径. 题解:二分半径即可.判断:假设当前二分到的半径是 R ,因为要和 x ...

  9. Letters CodeForces - 978C (二分)

    Time limit4000 ms Memory limit262144 kB There are nn dormitories in Berland State University, they a ...

随机推荐

  1. SqlSessionFactory

    源码: public interface SqlSessionFactory { SqlSession openSession(); SqlSession openSession(boolean va ...

  2. Angularjs 实现 $(document).ready()的两种方法

    1.在controller里面利用$on或者$watch bookControllers.controller('bookctrl_test', ['$scope', '$routeParams', ...

  3. 洛谷 P1454 圣诞夜的极光 == codevs 1293 送给圣诞夜的极光

    题目背景 圣诞夜系列~~ 题目描述 圣诞老人回到了北极圣诞区,已经快到12点了.也就是说极光表演要开始了.这里的极光不是极地特有的自然极光景象.而是圣诞老人主持的人造极光. 轰隆隆……烟花响起(来自中 ...

  4. 51nod 1417 天堂里的游戏

    基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 多年后,每当Noder看到吉普赛人,就会想起那个遥远的下午. Noder躺在草地上漫无目的的张望,二 ...

  5. Fire Air(华科校赛 网络赛)

    题目 原题链接:https://www.nowcoder.com/acm/contest/106/L 在100000 * 10000的空地上,有n个时间点,每个时间点会在(xi,yi)上种一棵树. 定 ...

  6. python_对字符串操作.join() 效率 比 + 效率高

    将列表中的字符拼接成字符串时,有两种方式 方式1:使用join()方法,将列表转为字符串 方式2:使用+运算符,循环遍历 import time str1 = ['a','b','c','d','e' ...

  7. Ubuntu 18的网络配置

    包括Ubuntu 18.04和18.10,设置为静态IP及DNS. sudo vim /etc/netplan/50-cloud-init.yaml network: ethernets: enp4s ...

  8. 使用 隧道技术 使用http代理连接 svn:// git://

    问题点 在某些情况下  无法通过代理 用 svn 访问svn://协议例如(svn://www.qdac.cc )   故此有了此贴 远端需要一个代理 服务器 connect-tunnel -P 代理 ...

  9. ImportError: pycurl: libcurl link-time ssl backend (nss) is different

    reference pip uninstall pycurl export PYCURL_SSL_LIBRARY=nss easy_install pycurl

  10. php添加了环境变更,还是显示 不是内部或外部命令 (注:添加到目录即可,不加 php.exe )

    重新配置了PHP环境,要安全PEAR扩展,CMD窗口运行PHP,提示不是内部或者外部命令或者可执行文件,解决方法是把PHP目录加入系统环境变量,不然的话,你只能CD到PHP安装目录下来运行PHP命令.