CF51C Three Base Stations
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的更多相关文章
- hdu 3879 Base Station 最大权闭合图
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3879 A famous mobile communication company is plannin ...
- 【二分】Base Station Sites @ICPC2017HongKong/upcexam5559
时间限制: 1 Sec 内存限制: 128 MB 5G is the proposed next telecommunications standards beyond the current 4G ...
- HDU 3879 Base Station
Base Station Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on HDU. Original I ...
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 GSM Base Station Identification (点在多边形内模板)
In the Personal Communication Service systems such as GSM (Global System for Mobile Communications), ...
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- poj 1195:Mobile phones(二维线段树,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14391 Accepted: 6685 De ...
- POJ 1195 二维树状数组
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 18489 Accepted: 8558 De ...
- ios抓包官方文档
OS X Programs OS X supports a wide range of packet trace programs, as described in the following sec ...
- HDU 4822 Tri-war(LCA树上倍增)(2013 Asia Regional Changchun)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4822 Problem Description Three countries, Red, Yellow ...
随机推荐
- C#语法——泛型的多种应用
本篇文章主要介绍泛型的应用. 泛型是.NET Framework 2.0 版类库就已经提供的语法,主要用于提高代码的可重用性.类型安全性和效率. 泛型的定义 下面定义了一个普通类和一个泛型类,我们可以 ...
- Linux下PAM模块学习总结
在Linux中执行有些程序时,这些程序在执行前首先要对启动它的用户进行认证,符合一定的要求之后才允许执行,例如login, su等.在Linux中进行身份或是状态的验证程序是由PAM来进行的,PAM( ...
- [JavaScript] 函数节流(throttle)和函数防抖(debounce)
js 的函数节流(throttle)和函数防抖(debounce)概述 函数防抖(debounce) 一个事件频繁触发,但是我们不想让他触发的这么频繁,于是我们就设置一个定时器让这个事件在 xxx 秒 ...
- NFS服务和DHCP服务讲解(week3_day2)--技术流ken
NFS服务端概述 NFS,是Network File System的简写,即网络文件系统.网络文件系统是FreeBSD支持的文件系统中的一种,也被称为NFS: NFS允许一个系统在网络上与他人共享目录 ...
- [JavaScript] requireJS基本使用
requireJS 是一个 AMD 规范的模块加载器主要解决的js开发的4个问题1. 异步加载,防止阻塞页面渲染2. 解决js文件之间的依赖关系和保证js的加载顺序3. 按需加载 来实现一个 requ ...
- Css-移动端适配总结
前言 工作以后,大部分的业务工作都是基于移动端H5的,开发过程中学习了很多东西,遇到过许多问题,诸如rem\em\css px\device px等,本文纯属个人的归纳总结,如有问题,请指出亲喷~ P ...
- 【译】《C# Tips -- Write Better C#》
[译]<C# Tips -- Write Better C#> <C# 奇淫巧技 -- 编写更优雅的 C#> 目录 介绍(Introduction) 第一部分:各种奇淫巧技(P ...
- 第十三课 CSS外观及样式的应用 css学习3
一.1.color: 文本颜色 预定义文本颜色值,如red,blue等 十六进制的颜色值 #fff白色 建议常用的表示方法 RGB代码,如红色可以表示为rgb(255,0,0)或rgb(100%,%0 ...
- Spring Boot 入门(五):集成 AOP 进行日志管理
本篇文章是接着 Spring boot 入门(四):集成 Shiro 实现登陆认证和权限管理写的,按照前面几篇博客的教程,可以搭建一个简单的项目,主要包含了 Pagehelper+MyBatis 分页 ...
- 结对编程项目总结 by:陈宏伟&刘益
结对编程项目在欢快的国庆假期中也顺利结束了.从最初拿到结对编程项目的思考,再到一步一步实现,中间经历了一个漫长的过程.在我和队友的多次协商下,最终我们还是选择使用基于python来实现这一次结对编程项 ...