D. Jumping Through Segments

显然是一个二分答案,关键是怎么搞判断函数?

我们维护合法的降落区间就好了~

// Problem: D. Jumping Through Segments
// Contest: Codeforces - Codeforces Round 913 (Div. 3)
// URL: https://codeforces.com/contest/1907/problem/D
// Memory Limit: 256 MB
// Time Limit: 5000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N = 2e5+10;
int n;
struct Edge{
	ll l,r;
}edge[N];

bool check(ll x){
	ll st =0,ed = 0;
	for(int i=1;i<=n;i++){
		
		st = max(st-x,edge[i].l);
		ed = min(ed+x,edge[i].r);
	    if(st>ed)return 0;
	}
	
	return 1;
	
}
void solve()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>edge[i].l>>edge[i].r;
	

	 ll l =-1,r = 1e9+10;
	 while(l+1!=r){
		 ll mid = (l+r)/2;
		 if(check(mid))r = mid;
		 else l =mid;
	 }

	cout<<r<<"\n";
	
	
	
	
}

int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int _;cin>>_;
	while(_--)solve();
	return 0;
}

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2023-12-06 23:18:03       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-06 23:18:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-06 23:18:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-06 23:18:03       18 阅读

热门阅读

  1. 基于深度学习的热红外与可见光图像融合

    2023-12-06 23:18:03       33 阅读
  2. git常用命令

    2023-12-06 23:18:03       43 阅读
  3. JVM

    JVM

    2023-12-06 23:18:03      39 阅读
  4. vue 组件通讯

    2023-12-06 23:18:03       31 阅读
  5. 二叉树的前、中和后序遍历的递归与迭代实现

    2023-12-06 23:18:03       27 阅读
  6. quickapp_快应用_DOM节点

    2023-12-06 23:18:03       34 阅读
  7. 第2节:Vue3 模板语法

    2023-12-06 23:18:03       33 阅读
  8. ReadWriteLock 和 StampedLock 的比较与解析

    2023-12-06 23:18:03       38 阅读
  9. 使用Redis实现购物车后端处理

    2023-12-06 23:18:03       34 阅读