CF51C Three Base Stations - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

题目描述

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 x_{i}xi​ coordinate. The village consists of nn houses, the ii -th house is located in the point with coordinates of x_{i}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 dd located in the point tt provides with communication all the houses on the segment [t-d,t+d][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 dd . Which minimal value of dd is enough to provide all the houses in the village with cellular communication.

输入格式

The first line contains an integer nn ( 1<=n<=2·10^{5}1<=n<=2⋅105 ) which represents the number of houses in the village. The second line contains the coordinates of houses — the sequence x_{1},x_{2},...,x_{n}x1​,x2​,...,xn​ of integer numbers ( 1<=x_{i}<=10^{9}1<=xi​<=109 ). It is possible that two or more houses are located on one point. The coordinates are given in a arbitrary order.

输出格式

Print the required minimal power dd . 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 00 to 2·10^{9}2⋅109 inclusively. It is accepted for the base stations to have matching coordinates. If there are many solutions, print any of them.

题意翻译

一句话题意:给定一条直线上n个点(可能重合),现在你有3个基地,你可以选择在三个地方放置这三个基地,每个基地有一个属性值d,假设将一个基地放在t的位置,那么他可以辐射到[t-d,t+d]范围内的所有的点,现在要你求出最小的d,以及这三个基地放置的位置,保留6位小数

输入输出样例

输入 #1

4
1 2 3 4

输出 #1

0.500000
1.500000 2.500000 3.500000

输入 #2

3
10 20 30

输出 #2

0
10.000000 20.000000 30.000000

输入 #3

5
10003 10004 10001 10002 1

输出 #3

0.500000
1.000000 10001.500000 10003.500000

思路

找最小的属性值d,因为当d取最大值的时候可以满足,往小的方向取,不一定满足,所以我们需要用二分去寻找最小的满足条件的d。然后通过函数check去判断:第一个基站肯定是要放在第一个基站往右mid的距离,这样是最优的,然后在通过上一个确定的基站,去寻找第一个没有覆盖到的点,如果在找完所有的点之前,已经有了3个基站了,则这种d不正确,需要重新去找,把二分的左边界右移;如果满足条件,能够把所有的基站全部包括,则将结果进行记录,再把二分的右边界左移,直到完成二分,最终的结果就是最优的了。

代码实现

#include<bits/stdc++.h>
using namespace std;
int n;
double a[200005],l,r,d,b[3],c[3];
int check(double x)
{int cnt=0;b[cnt]=a[cnt]+x;//第一个基站设在a[0]+d(d在这里为x)时最优,因为能最大限度覆盖到其他点for(int i=1; i<n; i++){if(a[i]>b[cnt]+x)//下一个基站就建在上一个基站不能覆盖到的第一个点a[i],然后放在a[i]+x的位置{if(cnt==2){return 0;}cnt++;b[cnt]=a[i]+x;}}for(int i=0; i<3; i++){c[i]=b[i];//记录基站位置}return 1;
}
int main()
{scanf("%d",&n);for(int i=0; i<n; i++){scanf("%lf",&a[i]);}sort(a,a+n);l=0,r=a[n-1];while(r-l>=1e-7) //精度误差{double mid=(l+r)/2;if(check(mid)==1){d=mid;r=mid-(1e-7);}else{l=mid+(1e-7);}}printf("%.6lf\n",d);printf("%.6lf %.6lf %.6lf",c[0],c[1],c[2]);return 0;
}

CF51C Three Base Stations相关推荐

  1. 第十一届山东省大学生程序设计竞赛 L. Construction of 5G Base Stations(概率期望,递推前缀和优化)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 第十一届山东省大学生程序设计竞赛 L. Construction of 5G Base Station ...

  2. Codeforces 51C Three Base Stations

    题意 https://codeforces.com/problemset/problem/51/C x x x水平轴上有 n ( ≤ 2 × 1 0 5 ) n(\le 2 \times 10^5) ...

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

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

  4. 第十一届山东省大学生程序设计竞赛题解(9 / 13)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 VP了一下,体验不是太好,区分度不是很好,简单题太简单,难题看着就不想写-没什么意思 比赛地址: ht ...

  5. 边缘计算Edage Computing

    1.边缘计算的定义 边缘计算是指在靠近物或数据源头的一侧,采用网络.计算.存储.应用核心能力为一体的开放平台,就近提供最近端服务. 其应用程序在边缘侧发起,产生更快的网络服务响应,满足行业在实时业务. ...

  6. 【 Notes 】MOBILE LOCALIZATON METHOD BASED ON MULTIDIMENSIONAL SIMILARITY ANALYSIS

    目录 ABSTRACT INTRODUCTION LINEAR TOA LOCALIZATION MULTIDIMENSIONAL SIMILARITY ANALYSIS SUBSPACE BASED ...

  7. 【 Notes 】COMPARISON OF BASIC METHODS AND POSITIONING SYSTEMS

    目录 COMPARISON OF BASIC METHODS AND POSITIONING SYSTEMS CONCLUSION, SUMMARY, AND FUTURE APPLICATIONS ...

  8. 【 Notes 】WLAN,Vision Positioning System,Radar

    目录 wireless local area network(WLAN) Vision Positioning System Radar wireless local area network(WLA ...

  9. 【 Notes 】 AGPS or Assisted GPS

    Assisted Global Positioning System ( AGPS or Assisted GPS ) GPS operation was summarized in the prev ...

最新文章

  1. python psycopg2_Ubuntu 安装 PostgreSQL 和 python-psycopg2基础教程(以及错误解决)
  2. html抽奖源码_开源FPGA开发板OpenICE 介绍及抽奖
  3. 利用rpm包搭建lamp环境及论坛的创建
  4. Keepalived+Nginx实现高可用负载均衡集群
  5. 这是Blazor上传文件的最佳方式吗?
  6. Dapr闪电说 - Dapr落地云原生架构
  7. WPF Treeview第三层横向排列
  8. 尚硅谷李老师笔记3DQL
  9. 爱荷华大选 App 投票酿闹剧的反思:为什么我们在软件工程方面如此糟糕?
  10. Excel-VBA操作文件四大方法之一(1/4)
  11. progressDialog 为什么设置了setProgress()方法无反应?
  12. win7如何调整计算机c盘,Win7系统增加C盘空间的方法
  13. 家里电脑怎么控制公司电脑?电脑远程控制的几种方式
  14. 医疗行业安全建设方案
  15. 实习期间的一些思考整理(1)2018.4.8~4.9
  16. 28-Docker-常用命令详解-docker save/load/import
  17. .NET MongoDB Driver GridFS 2.2原理及使用示例
  18. Creator3D:shader14_噪声消融
  19. 深度优先搜索-Python
  20. 什么才是程序员的内功心法?

热门文章

  1. 01--2017年同济大学公共课复习总结
  2. iPhone的刘海屏和home键解决方案
  3. Unity_代码方式添加绑定按钮点击事件
  4. 处理器哪个好_天玑720和麒麟985处理器哪个好-参数性能对比
  5. GAN初探:模拟高斯分布
  6. 十、获取人体骨骼关键点三维坐标——Azure Kinect DK入门
  7. 浪涌保护器的前端防线:SCB后备保护器
  8. git分支及如何解决合并冲突问题
  9. win11桌面文件在哪个文件夹?
  10. 修改滚动条的背景颜色和滚动条颜色