codeforces 1041 d 二分
题意转化:有一些区间,要求选一些连续的区间。两两区间间隔的和要求小于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 二分的更多相关文章
- codeforces 1041 e 构造
Codeforces 1041 E 构造题. 给出一种操作,对于一棵树,去掉它的一条边.那么这颗树被分成两个部分,两个部分的分别的最大值就是这次操作的答案. 现在给出一棵树所有操作的结果,问能不能构造 ...
- codeforces 1165F1/F2 二分好题
Codeforces 1165F1/F2 二分好题 传送门:https://codeforces.com/contest/1165/problem/F2 题意: 有n种物品,你对于第i个物品,你需要买 ...
- codeforces 732D(二分)
题目链接:http://codeforces.com/contest/732/problem/D 题意:有m门需要过的课程,n天的时间可以选择复习.考试(如果的d[i]为0则只能复习),一门课至少要复 ...
- CodeForces 359D (数论+二分+ST算法)
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=47319 题目大意:给定一个序列,要求确定一个子序列,①使得该子序 ...
- CodeForces 163B Lemmings 二分
Lemmings 题目连接: http://codeforces.com/contest/163/problem/B Descriptionww.co As you know, lemmings li ...
- CodeForces - 589A(二分+贪心)
题目链接:http://codeforces.com/problemset/problem/589/F 题目大意:一位美食家进入宴会厅,厨师为客人提供了n道菜.美食家知道时间表:每个菜肴都将供应. 对 ...
- 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 ...
- CodeForces - 1059D(二分+误差)
链接:CodeForces - 1059D 题意:给出笛卡尔坐标系上 n 个点,求与 x 轴相切且覆盖了所有给出点的圆的最小半径. 题解:二分半径即可.判断:假设当前二分到的半径是 R ,因为要和 x ...
- Letters CodeForces - 978C (二分)
Time limit4000 ms Memory limit262144 kB There are nn dormitories in Berland State University, they a ...
随机推荐
- JVM补充一
一.为什么废弃永久代(PermGen) 2.1 官方说明 参照JEP122:http://openjdk.java.net/jeps/122,原文截取: Motivation This is part ...
- Oracle创建用户及权限设置
oracle用户创建及权限设置 权限: create session create table unlimited tablespace connect resource dba 例: #sqlplu ...
- mongodb多条件查询总结
根据两字段乘积过滤查询分页数据 db.cron.aggregate([{$project:{_id:,AppID:,result:{$add:["$endlottery",&quo ...
- Summary of 2016 International Trusted Computing and Cloud Security Summit
1) Welcome Remarks 2) The advancement of Cloud Computing and Tursted Computing national st ...
- axure使用经验
泛化不常用======伸展也是拉动原件收缩也是拉动原件====== 动态模板相互影响(有的时候会出现这个问题,只需要设置两者的高度,不让两者有包含关系(一点点可以有):====== 实现高级菜单栏(同 ...
- activitmq+keepalived+nfs 非zk的高可用集群构建
nfs 192.168.10.32 maast 192.168.10.4 savel 192.168.10.31 应对这个需求既要高可用又要消息延迟,只能使用变态方式实现 nfs部署 #yum ins ...
- html自动刷新
头部<meta http-equiv="refresh" content="10"> 或者js实现 <script language=&quo ...
- HTML页面中5种超酷的伪类选择器:hover效果
想在自己的网站中应用超酷的hover效果吗?也许你可以从如下的这些实例中获得一些灵感,如果你喜欢这些效果,也可以直接拷贝代码并应用到你的站点. 给平淡的站点带来活力 hover效果能给网页增加一些动态 ...
- 洛谷——P1627 [CQOI2009]中位数
P1627 [CQOI2009]中位数 给出1~n的一个排列,统计该排列有多少个长度为奇数的连续子序列的中位数是b.中位数是指把所有元素从小到大排列后,位于中间的数. 中位数的题目有关统计的话,可以转 ...
- UVa-340-猜数字
#include <stdio.h> char ans[1000],gus[1000]; int num[10]; int main() { int n,cnt=1; while (sca ...