https://codeforces.com/problemset/problem/51/C

题目

The New Vasjuki village is stretched along the motorway and that's why every house on it is characterized by its shift relative to some fixed point — the xi coordinate. The village consists of n houses, the i-th house is located in the point with coordinates of xi.

TELE3, a cellular communication provider planned to locate three base stations so as to provide every house in the village with cellular communication. The base station having power d located in the point t provides with communication all the houses on the segment [t - d, t + d] (including boundaries).

To simplify the integration (and simply not to mix anything up) all the three stations are planned to possess the equal power of d. Which minimal value of d is enough to provide all the houses in the village with cellular communication.

Input

The first line contains an integer n (1 ≤ n ≤ 2·105) which represents the number of houses in the village. The second line contains the coordinates of houses — the sequence x1, x2, ..., xn of integer numbers (1 ≤ xi ≤ 109). It is possible that two or more houses are located on one point. The coordinates are given in a arbitrary order.

Output

Print the required minimal power d. In the second line print three numbers — the possible coordinates of the base stations' location. Print the coordinates with 6 digits after the decimal point. The positions of the stations can be any from 0 to 2·109 inclusively. It is accepted for the base stations to have matching coordinates. If there are many solutions, print any of them.

题解

二分+贪心

二分功率,贪心验证能否成立……

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<iomanip> #define REP(r,x,y) for(register int r=(x); r<(y); r++)
#define REPE(r,x,y) for(register int r=(x); r<=(y); r++)
#ifdef sahdsg
#define DBG(...) printf(__VA_ARGS__)
#else
#define DBG(...) (void)0
#endif using namespace std;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii; #define MAXN 200007
#define EPS 1e-3
int n;
int arr[MAXN]; char ch; int f;
inline void read(int &x) {
x=0; f=1; do ch=getchar(); while(!isdigit(ch) && ch!='-');
if(ch=='-') ch=getchar(),f=-1; while(isdigit(ch)) {x=x*10+ch-'0';
ch=getchar();} x*=f;
} inline int ub(int f, int t, double x) {
while(f<t) {
int m=(f+t)>>1;
if(arr[m]<=x) f=m+1;
else t=m;
}
return f;
} inline int lb(int f, int t, double x) {
while(f<t) {
int m=(f+t)>>1;
if(arr[m]<x) f=m+1;
else t=m;
}
return f;
} inline bool vali(double m) {
int s=arr[0], x=0;
REP(i,0,3) {
x=ub(x, n, s+m);
if(x>=n) {return 1;}
s=arr[x];
}
DBG("#%d\n", x);
return false;
} int main() {
read(n);
REP(i,0,n) {
read(arr[i]);
} sort(arr,arr+n);
double l=0, r=1e9;
while(r-l>EPS) {
double m = (l+r)/2;
if(vali(m)) {
r=m;
} else {
l=m;
}
}
printf("%.2f\n", r/2);
int s=arr[0], x=0;
REP(i,0,3) {
if(i) putchar(' ');
int lx=ub(x, n, s+r)-1; printf("%f", (arr[lx]+arr[x])/2.0);
x=lx+1;
if(x>=n) {
for(i++;i<3;i++) {
if(i) putchar(' '); printf("0");
}
return 0;
}
s=arr[x];
} return 0;
}

CF51C Three Base Stations的更多相关文章

  1. hdu 3879 Base Station 最大权闭合图

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3879 A famous mobile communication company is plannin ...

  2. 【二分】Base Station Sites @ICPC2017HongKong/upcexam5559

    时间限制: 1 Sec 内存限制: 128 MB 5G is the proposed next telecommunications standards beyond the current 4G ...

  3. HDU 3879 Base Station

    Base Station Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on HDU. Original I ...

  4. 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 GSM Base Station Identification (点在多边形内模板)

    In the Personal Communication Service systems such as GSM (Global System for Mobile Communications), ...

  5. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  6. poj 1195:Mobile phones(二维线段树,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14391   Accepted: 6685 De ...

  7. POJ 1195 二维树状数组

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 18489   Accepted: 8558 De ...

  8. ios抓包官方文档

    OS X Programs OS X supports a wide range of packet trace programs, as described in the following sec ...

  9. HDU 4822 Tri-war(LCA树上倍增)(2013 Asia Regional Changchun)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4822 Problem Description Three countries, Red, Yellow ...

随机推荐

  1. Spring Boot配置定时任务

    在项目开发过程中,经常需要定时任务来做一些内容,比如定时进行数据统计(阅读量统计),数据更新(生成每天的歌单推荐)等. Spring Boot默认已经实现了,我们只需要添加相应的注解就可以完成定时任务 ...

  2. SLAM+语音机器人DIY系列:(一)Linux基础——2.安装Linux发行版ubuntu系统

    摘要 由于机器人SLAM.自动导航.语音交互这一系列算法都在机器人操作系统ROS中有很好的支持,所以后续的章节中都会使用ROS来组织构建代码:而ROS又是安装在Linux发行版ubuntu系统之上的, ...

  3. 【转载】java 中 String s = new String("abc") 创建了几个对象?!

    原文链接点这里,感谢博主分享 答案是两个,现在我们具体的说一下: String s = new String("abc"); 首先我们要明白两个概念,引用变量和对象,对象一般通过n ...

  4. C#复制文件全代码--供参考

    private void button1_Click(object sender, EventArgs e) { //创建文件对象 FileInfo fi = null; //实例化打开文件对话框 O ...

  5. .net接收post请求,并转为字符串

    Stream s = Request.InputStream; int count = 0; byte[] buffer = new byte[1024]; StringBuilder reqXml ...

  6. 用python写一个北京市的个税计算器

    #应纳税的钱:税前收入-5000元(起征点)-专项扣除(五险一金等) #工资个税的计算公式为: #个人所得税=应纳税的钱×适用税率-速算扣除数 ''' 1.全月应纳税所得额不超过3000元: 税率:3 ...

  7. 委托的多线程方法BeginInvoke

    同步方法和异步方法: 同步方法调用在程序继续执行之前需要等待同步方法执行完毕返回结果.(比如烧水泡茶,需要等水烧开了才能继续泡茶) 异步方法则在被调用之后立即返回以便程序在被调用方法完成其任务的同时执 ...

  8. 前端入门20-JavaScript进阶之异步回调的执行时机

    声明 本系列文章内容全部梳理自以下几个来源: <JavaScript权威指南> MDN web docs Github:smyhvae/web Github:goddyZhao/Trans ...

  9. EclipseAndroid打包签名发布安装失败闪退运行不了

    EclipseAndroid打包签名发布安装失败闪退运行不了 本来没怎么用过用Eclipse写安卓,可是有人有需要必须用Eclipse写,那就写呗. 可在签名打包的时候,发到手机上安装,提示安装成功. ...

  10. DEDE整站动态/静态转换

    方法一:使用DEDE后台的SQL命令行工具 入口:织梦后台-系统-SQL命令行工具 DEDE整站动态化 将所有栏目设置为“使用动态页”: 将所有文档设置为“仅动态”: DEDE整站静态化 将所有栏目设 ...