博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF-51C - Three Base Stations(二分或枚举优化)
阅读量:5361 次
发布时间:2019-06-15

本文共 3124 字,大约阅读时间需要 10 分钟。

C - Three Base Stations
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
     

Description

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.

Sample Input

Input
41 2 3 4
Output
0.5000001.500000 2.500000 3.500000
Input
310 20 30
Output
010.000000 20.000000 30.000000
Input
510003 10004 10001 10002 1
Output
0.5000001.000000 10001.500000 10003.500000

本题有两种思路:一种,枚举三段,找最小,然后优化,第二种,使用二分距离判断是否符合条件。本题有个隐藏条件,那就最终的距离只可能是前面一个整数,后面跟个0.5或0.

#include
#include
#include
#include
using namespace std;const int mm=2e5+9;const int oo=1e9;int dis[mm];int n;double a,b,c,len=oo;void ok(int x,int y){ if(y<0)y=0; int z; z=dis[x]-dis[0]; z=max(dis[y]-dis[min(x+1,n-1)],z); z=max(dis[n-1]-dis[min(y+1,n-1)],z); if(z
dis[j]-dis[i+1]) ++j; ok(i,j);ok(i,j-1); } len/=2.0;a/=2.0;b/=2.0;c/=2.0; printf("%.6lf\n%.6lf %.6lf %.6lf\n",len,a,b,c);}
二分代码

#include
#include
#include
#include
using namespace std;const int mm=2e5+9;const double oo=1e39;const double ex=1e-7;double locat[mm];int n,ans[mm];int blook(int x)///返回比x大的第一个数的下标{ int l=0,r=n,mid=(l+r)/2; while(l
x)r=mid; else l=mid+1; mid=(l+r)/2; } return mid;}bool ok(int x){ int z=0; for(int i=0;i<3;i++) { z=blook(locat[z]+x); ans[i]=z; if(z==n)return 1; } return 0;}int main(){ while(cin>>n) { for(int i=0;i
>locat[i]; sort(locat,locat+n); int r=2e9+9,l=0,mid; while(l

转载于:https://www.cnblogs.com/nealgavin/archive/2013/03/20/3206120.html

你可能感兴趣的文章
给mysql数据库字段值拼接前缀或后缀。 concat()函数
查看>>
迷宫问题
查看>>
【FZSZ2017暑假提高组Day9】猜数游戏(number)
查看>>
泛型子类_属性类型_重写方法类型
查看>>
练习10-1 使用递归函数计算1到n之和(10 分
查看>>
Oracle MySQL yaSSL 不明细节缓冲区溢出漏洞2
查看>>
Code Snippet
查看>>
zoj 1232 Adventure of Super Mario
查看>>
组合数学 UVa 11538 Chess Queen
查看>>
Redis常用命令
查看>>
[转载]电脑小绝技
查看>>
windos系统定时执行批处理文件(bat文件)
查看>>
thinkphp如何实现伪静态
查看>>
BZOJ 1925: [Sdoi2010]地精部落( dp )
查看>>
c++中的string常用函数用法总结!
查看>>
Week03-面向对象入门
查看>>
一个控制台程序,模拟机器人对话
查看>>
Vue 2.x + Webpack 3.x + Nodejs 多页面项目框架(上篇——纯前端多页面)
查看>>
我的PHP学习之路
查看>>
【题解】luogu p2340 奶牛会展
查看>>