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

感谢何骐的提醒。

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

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. List<string>绑定到DataGridView控件

    问题 将一个简单的List<string>作为数据源绑定到 DataGridView myDataGridView.DataSource = myStringList; 但是只得到一个名为 ...

  2. Day 26:Dom4j修改xml

    Dom4j:Writing a document to a file import java.io.File; import java.io.FileOutputStream; import org. ...

  3. mysql更新某一列数据

    UPDATE 表名 SET 字段名 = REPLACE(替换前的字段值, '替换前关键字', '替换后关键字'); select * from province; +----+------------ ...

  4. SYSTEMTIME 获取日期之差

    #include <windows.h> #include <stdio.h> #include <stdlib.h> #include <string.h& ...

  5. windowsXP下 使用live555搭建视频服务器,并使用ffplay和VLC播放

    首先在官网下载live555:http://www.live555.com/mediaServer/#downloading当然是现在windows的版本了!!上官网下载FFmpeg:http://f ...

  6. IDEA 分屏显示

    效果: 步骤: 对着某个标签页单击右键,选择Split Vertically或者Split Horizontally即可.

  7. [转载]Jquery Chosen 插件动态生成option或重新绑定

    $(".chosen—select").find("option[value='1']").attr("selected", "s ...

  8. PhotoView 实现与图片进行简单的交互

    本文的category是根据VIPhotoView来做参考,在此基础上添加个加载网络图片. 此category主要功能是与图片进行交互,双击放大图片,捏合等操作. 感谢vitoziv ! VIPhot ...

  9. Windows + Python + flup + flask + fastcgi + Nginx配置

    Nginx配置 # HTTPS server { listen ssl; server_name kvaccount.xx.io; ssl_certificate "C:/xx/conf/s ...

  10. [NCTF2019]Fake XML cookbook

    0x00 知识点 XXE攻击 附上链接: https://xz.aliyun.com/t/6887 XXE(XML External Entity Injection)全称为XML外部实体注入 XML ...