校队选拔神马的事情就不说了,哥们反正是要崛起的人了!

感谢何骐的提醒。

校队选拔的时候又被二分给坑了,所以还想做几道二分搜索的题目来练练手。

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
4
1 2 3 4
Output
0.500000
1.500000 2.500000 3.500000
Input
3
10 20 30
Output
0
10.000000 20.000000 30.000000
Input
5
10003 10004 10001 10002 1
Output
0.500000
1.000000 10001.500000 10003.500000

初看这个题目的时候,我以为又是切蛋糕那种题目,二分一个浮点数,(事实上根据网上博客贴的代码,有人这样做也可以过)。但是后来接触到一种思路,事实上点坐标都是整数,所以站点的覆盖范围,即覆盖圆的直径,必定是一个整数,故,只要二分覆盖圆的直径,即可。

关于最后还要输出每个站点的具体坐标,一个好的方法是在二分时用个数组记录每建立一个覆盖点后,覆盖到的点的下一点。这样,求坐标的时候,还是在代码里面说吧

比较坑的是第一组数据,我为这个纠结了好久,明显的在第一组数据中,两个站点就可以覆盖4个点,第三个站点随便怎么放,但我以为一定要按样例,改来改去,都没法统一

结果发现根本就不用管这个破第一组样例,也过了。可能像这种数据,随便站点怎么放,只要能覆盖就过了吧。

#include <iostream>
#include <cstdio>
#include <cstring>
#define maxn 200000
#include <algorithm>
using namespace std;
int loc[maxn+];
int n;
int ans[];
int fnext(int y) //用来找到当前覆盖圆覆盖后的最近一个覆盖点。
{
int l=,r=n+,mid=(l+r)/;
while (l<r)
{ if (loc[mid]<=y)
l=mid+;
else
r=mid;
mid=(l+r)/;
}
return mid;
}
int ok(int x)
{
int i,j;
int z=;
for (i=; i<=; i++)
{ z=fnext(loc[z]+x);
ans[i]=z; //用这个数组来记录覆盖圆的下一个点。
//cout<<x<<" "<<z<<endl;
if (z>=n+) return ;
} return ;
}
int main()
{ while (scanf("%d",&n)!=EOF)
{
int i,j,k;
for (i=; i<=n; i++)
{
scanf("%d",&loc[i]);
//cout<<loc[i]<<endl;
}
sort(loc+,loc+n+);
//loc[n+1]=loc[n];
int r=(loc[n]-loc[]);
int l=,mid;
while (l<r) //二分覆盖圆的直径
{
mid=(r+l)/;
if (ok(mid)) r=mid;
else l=mid+;
}
ok(l);
//cout<<ans[1]<<" "<<ans[2]<<" "<<ans[3]<<endl;
double radius=l*1.0/2.0;
double radar1=(loc[ans[]-]+loc[])*1.0/2.0;
double radar2=(loc[ans[]-]+loc[ans[]])/2.0;//前点加后点再除以2的方式得到圆心坐标
double radar3=(loc[ans[]-]+loc[ans[]])/2.0;
printf("%.6f\n",radius);
printf("%.6f ",radar1);
printf("%.6f ",radar2);
printf("%.6f\n",radar3);
}
return ;
}

CodeForces 51C 二分搜索的更多相关文章

  1. 二分搜索 Codeforces Round #299 (Div. 2) C. Tavas and Karafs

    题目传送门 /* 题意:给定一个数列,求最大的r使得[l,r]的数字能在t次全变为0,每一次可以在m的长度内减1 二分搜索:搜索r,求出sum <= t * m的最大的r 详细解释:http:/ ...

  2. 二分搜索 Codeforces Round #218 (Div. 2) C. Hamburgers

    题目传送门 /* 题意:一个汉堡制作由字符串得出,自己有一些原材料,还有钱可以去商店购买原材料,问最多能做几个汉堡 二分:二分汉堡个数,判断此时所花费的钱是否在规定以内 */ #include < ...

  3. Codeforces Round #448 (Div. 2) B. XK Segments【二分搜索/排序/查找合法的数在哪些不同区间的区间数目】

    B. XK Segments time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. codeforces 1019B The hat 【交互题+二分搜索】

    题目链接:戳这里 学习题解:戳这里

  5. codeforces 483B Friends and Presents 解题报告

    题目链接:http://codeforces.com/problemset/problem/483/B 题目意思:有两个 friends,需要将 cnt1 个不能整除 x 的数分给第一个friend, ...

  6. CodeForces - 363D --二分和贪心

    题目:CodeForces - 363D 题意:给定n个学生,其中每个学生都有各自的私己钱,并且自己的私己钱只能用在自己买自行车,不能给别人. 给定m个自行车,每个自行车都有一个价格. 给定公有财产a ...

  7. CodeForces 551C - GukiZ hates Boxes - [二分+贪心]

    题目链接:http://codeforces.com/problemset/problem/551/C time limit per test 2 seconds memory limit per t ...

  8. Educational Codeforces Round 55 (Rated for Div. 2) B. Vova and Trophies 【贪心 】

    传送门:http://codeforces.com/contest/1082/problem/B B. Vova and Trophies time limit per test 2 seconds ...

  9. Codeforces Round #404 (Div. 2) C 二分查找

    Codeforces Round #404 (Div. 2) 题意:对于 n and m (1 ≤ n, m ≤ 10^18)  找到 1) [n<= m] cout<<n; 2) ...

随机推荐

  1. 061、Java中利用return结束方法调用

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  2. 7.6 CLI 管理Varnish

    ./varnishd -f /usr/common/varnish/etc/varnish/ -a 测试: 代理tomcat服务器地址:http://172.20.10.5:1111/ telnet ...

  3. html5移动端主流适配方案

    1.流式布局(百分比布局)    案例:京东移动端 优点:简单方便,只需要固定高度,宽度自适应: 缺点:大屏幕手机实际显示的不协调. 2.响应式布局 优点:可以节约成本,不用再做专门的web app网 ...

  4. Golang的标准输入输出

    Golang的标准输入输出 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 在很多情况下,我们希望用户通过键盘输入一个数值,存储到某个变量中,然后将该变量的值取出来,进行操作.这时候 ...

  5. 关于Arduino MEGA2560 看门狗对bootloader的依赖

    bootloader在Arduino中起着至关重要的位置,arduino-1.5.6-r2版本中的bootloader对看门狗(watchdog)的bug进行了修复:mega2560其实就是使用的AV ...

  6. Python序列内单双引的问题——未解决

    在学习python基础的时候,遇到这样一个问题: tuple=(2,2.3,"yeah",5.6,False)list=[True,5,"smile"] 这样输 ...

  7. jquery实现常用UI布局

    tab html <div class="tab"> <ul class="tab-title"> <li class=" ...

  8. Vulkan SDK 之 Graphics Pipeline

    A graphics pipeline consists of shader stages, a pipeline layout, a render pass, and fixed-function ...

  9. maven详解之仓库

    在Maven中,任何一个依赖.插件或者项目构建的输出,都可以称之为构件. Maven在某个统一的位置存储所有项目的共享的构件,这个统一的位置,我们就称之为仓库.(仓库就是存放依赖和插件的地方) 任何的 ...

  10. 基于Windows平台的Python多线程及多进程学习小结

    python多线程及多进程对于不同平台有不同的工具(platform-specific tools),如os.fork仅在Unix上可用,而windows不可用,该文仅针对windows平台可用的工具 ...