#include<bits/stdc++.h>
using namespace std;
int n;
struct Node{
int a;
int b;
};
vector<Node> s;
bool ngreater(Node x, Node y){
return x.b < y.b;
}
bool check(int mid){
vector<Node> temp(s);
int mr = 0;
while(true){
bool flag = false;
for(int i = 0; i < temp.size(); i++){
int x = temp[i].a;
int y = temp[i].b;
int len = y - x;
if(x - mid <= mr && y + mid >= mr){
flag = true;
if(x + mid >= mr){
mr += len;
}
else{
mr = y + mid;
}
temp.erase(temp.begin() + i);
break;
}
}
if(mr >= 20000 || !flag) break;
}
return mr >= 20000;
}
int main()
{
cin >> n;
for(int i = 0; i < n; i++){
int x, y;
scanf("%d%d", &x, &y);
s.push_back({x * 2, y * 2});
}
sort(s.begin(), s.end(), ngreater);
int mid;
int min;
int left = 0, right = 20000;
while(left <= right){
mid = (left + right) >> 1;
if(check(mid)){
right = mid - 1;
min = mid;
}
else{
left = mid + 1;
}
}
double res = ((double)min) / 2;
cout << res;
}
【蓝桥-2017国赛】【二分】6.区间位移
最新推荐文章于 2025-04-03 19:48:35 发布