【二分】Base Station Sites @ICPC2017HongKong/upcexam5559
时间限制: 1 Sec 内存限制: 128 MB
5G is the proposed next telecommunications standards beyond the current 4G standards. 5G planning aims at higher capacity than current 4G, allowing a higher density of mobile broadband users, and supporting device-to- device, reliable, and massive wireless communications. A telecommunication company would like to install more base stations to provide better communication for customers. Due to the installation cost and available locations,the company can only install S (2 ≤ S ≤ L) base stations at L (2 ≤ L ≤ 100, 000) candidate locations. Since the base stations work in the same frequency band, they will interfere and cause severe performance degradation. To provide high quality communication experience to customers, the company would like to maximize the distance between the base stations so as to reduce the wireless interference among the base stations. Suppose the L candidate locations are in a straight line at locations P1, P2,…, PL (0 ≤ Pi ≤ 1, 000, 000) and the company wants to install S base stations at the L candidate locations. What is the largest minimum distance among the S base stations?
The input data includes multiple test sets.
Each set starts with a line which specifies L (i.e., the number of candidate locations) and S (i.e., the number of base stations). The next line contains L space-separated integers which represent P1, P2,…, PL.
The input data ends “0 0”.
For each set, you need to output a single line which should be the largest minimum distance among the base stations.sample input
5 3
2 3 9 6 11
4 3
1 4 9 10
0 0sample output
4
给你L个点,要你选S个点,要求这些点之间的最小距离最大,输出这个最大值
二分答案
#define IN_PC() freopen("C:\\Users\\hz\\Desktop\\in.txt","r",stdin)
#define OUT_PC() freopen("C:\\Users\\hz\\Desktop\\out.txt","w",stdout)
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int L,S,P[maxn];
bool judge(int _val) {
int ret = 1;
int las = P[0];
for(int i = 1; i<L; i++) {
if(P[i]-las>=_val) {
ret++;
las = P[i];
}
}
return ret>=S;
}
int main() {
// IN_PC();
// OUT_PC();
while(scanf("%d%d",&L,&S)&&!(L==0&&S==0)) {
for(int i=0; i<L; i++) {
scanf("%d",P+i);
}
sort(P,P+L);
int l = 0,r = 1000005;
while(l<r) {
int mid = ((l+r)%2)?((l+r)/2+1):((l+r)/2);
if(judge(mid))
l = mid;
else
r = mid-1;
}
printf("%d\n",(l+r)/2);
}
return 0;
}
【二分】Base Station Sites @ICPC2017HongKong/upcexam5559的更多相关文章
- hdu3879 Base Station 最大权闭合子图 边权有正有负
/** 题目:hdu3879 Base Station 最大权闭合子图 边权有正有负 链接:http://acm.hdu.edu.cn/showproblem.php?pid=3879 题意:给出n个 ...
- 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), ...
- hdu 3879 Base Station 最大权闭合图
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3879 A famous mobile communication company is plannin ...
- HDU 3879 Base Station(最大权闭合子图)
经典例题,好像说可以转化成maxflow(n,n+m),暂时只可以勉强理解maxflow(n+m,n+m)的做法. 题意:输入n个点,m条边的无向图.点权为负,边权为正,点权为代价,边权为获益,输出最 ...
- HDU 3897 Base Station (网络流,最大闭合子图)
题意:给定n个带权点m条无向带权边,选一个子图,则这个子图的权值为 边权和-点权和,求一个最大的权值. 析:把每条边都看成是一个新点,然后建图,就是一个裸的最大闭合子图. 代码如下: #pragma ...
- HDU 3879 Base Station(最大权闭合子图)
将第i个用户和他需要的基站连边,转化成求二分图的最大权闭合子图. 答案=正权点之和-最小割. # include <cstdio> # include <cstring> # ...
- ACdream 1127 Base Station (离线查询+树状数组)
题目链接: http://acdream.info/problem?pid=1127 题目: 移动通信系统中,通信网的建立主要通过基站来完成. 基站可以分为主基站和子基站.子基站和各个移动用户进行连接 ...
- HDU 3879 && BZOJ 1497:Base Station && 最大获利 (最大权闭合图)
http://acm.hdu.edu.cn/showproblem.php?pid=3879 http://www.lydsy.com/JudgeOnline/problem.php?id=1497 ...
随机推荐
- 关于64位 MS SQL 导入导出 Oracle 引发 ORA-06413 的解决方法
如果在X64系统下我们想利用 MS SQL 的DTS导入导出 Oracle 数据,由 oracle 不支持路径中包含")",会引发 ORA-06413:连接未打开错误 解决的办法很 ...
- Android设备一对多录屏直播--(UDP组播连接,Tcp传输)
原文:https://blog.csdn.net/sunmmer123/article/details/82734245 近期需要学习流媒体知识,做一个Android设备相互投屏Demo,因此找到了这 ...
- 一个良好划分Activity创建步骤的BaseActivity
一个Activity的创建过程其实包含几个不同的步骤,基本上都是在onCreate函数中完成的,这些步骤主要有: 设置页面的布局文件 初始化页面包含的控件 设置页面控件的点击响应事件 处理页面的业务逻 ...
- NPOI导出Excel帮助类
工具类 using System; using System.Collections.Generic; using System.Data; using System.IO; using System ...
- 一起学Hive——创建内部表、外部表、分区表和分桶表及导入数据
Hive本身并不存储数据,而是将数据存储在Hadoop的HDFS中,表名对应HDFS中的目录/文件.根据数据的不同存储方式,将Hive表分为外部表.内部表.分区表和分桶表四种数据模型.每种数据模型各有 ...
- NLS_CHARACTERSET和NLS_NCHAR_CHARACTERSET
The NLS_CHARACTERSET is used for CHAR, VARCHAR2, LONG and CLOB columns;The NLS_NCHAR_CHARACTERSET is ...
- Python_xml
xml: 可扩展标记语言,用来标记数据,定义数据类型,主要用来传输和存储数据(和json差不多,不同语言或程序之间进行数据交换的协议) ET(xml.etree.ElementTree)中的几个类: ...
- Balanced Number 数位dp
题意: 给出求ab之间有多少个平衡数 4139为平衡数 以3为轴 1*1+4*2==9*1 思路很好想但是一直wa : 注意要减去前导零的情况 0 00 000 0000 不能反复计 ...
- Debian 9 VIM 使用鼠标右键复制
起因 装了 debian 9 以后,vim没有办法使用鼠标直接选择并复制,后来发现是默认的配置问题.于是需要按照以下方式解决: 解决方法 1. 编辑 vim 的默认配置文件 vim /usr/shar ...
- GUI:GUI的方式创建/训练/仿真/预测神经网络—Jason niu
(1)导入数据:点击最左底部Import 按钮 (2)创建模型network_Jason_niu:点击底部的New按钮 (3)设置参数并训练:点击底部的Open按钮 (4)仿真预测: 大功告成!