Acwing5048. 无线网络 题解(二分)

输入样例1:
4
1 2 3 4
输出样例1:
0.500000
1.500000 2.500000 3.500000
输入样例2:
3
10 20 30
输出样例2:
0
10.000000 20.000000 30.000000
输入样例3:
5
10003 10004 10001 10002 1
输出样例3:
0.500000
1.000000 10001.500000 10003.500000
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int n,x[N];vector<double>dist;
bool check(double r){
    dist.clear();
    dist.push_back(x[0]+r);
    for(int i=1;i<n;i++){
        if(x[i]>dist.back()+r){
            if(dist.size()==3)return false;
            dist.push_back(x[i]+r);//!!!
        }
    }
    return true;
}
int main(){
    cin>>n;for(int i=0;i<n;i++)cin>>x[i];
    sort(x,x+n);double l=0,r=(x[n-1]-x[0])/2;
    while(r-l>1e-7){
        double mid=(l+r)/2;
        if(check(mid))r=mid;else l=mid;
    }
    printf("%lf\n",r);
    check(r);
    while (dist.size()<3) dist.push_back(x[0]);
    for (auto t: dist)
        printf("%lf ", t);
    return 0;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值