ACM-ICPC 2017 Asia HongKong - E (二分答案)

10 篇文章 0 订阅

 

5G is the proposed next telecommunications standards beyond the current 4G4G standards. 5G5G planning aims at higher capacity than current 4G4G, allowing a higher density of mobile broadband users, and supporting device-to- device, reliable, and massive wireless communications. AA 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)S(2≤SL) base stations at L(2≤L≤100,000)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)P1​,P2​,...,PL(0≤Pi≤1,000,000) and the company wants to install SS base stations at the LL candidate locations. What is the largest minimum distance among the SS base stations?

Input

The input data includes multiple test sets.

Each set starts with a line which specifies LL (i.e.i.e., the number of candidate locations) and SS (i.e.i.e., the number of base stations). The next line contains LL space-separated integers which represent P1P1​ , P2P2​ , ... , PLPL​ . The input data ends “00 00”.

Output

For each set, you need to output a single line which should be the largest minimum distance among the base stations.

For the first set, the 33 base stations can be installed at locations 2,6,112,6,11.

样例输入

5 3
2 3 9 6 11
4 3
1 4 9 10
0 0

样例输出

4
3

题目来源

ACM-ICPC 2017 Asia HongKong

 

题意:

 

给你一维上的数个点,你要从中选出S个点,算出他们相对的最短距离。 输出最大的最短距离。

 

POINT:

二分答案,每次看看这个答案能不能有效就行了。这个过程只要o(N).扫一遍就行了。

 

#include <iostream>
#include <stdio.h>
#include <cmath>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long LL;
const LL maxn = 100000+33;
const LL inf = 0x3f3f3f3f;
int a[maxn];
int l,s;

bool check(int x)
{
	int num = 1;
	int now = a[1];
	for(int i=2;i<=l;i++){
		if(a[i]-now>=x){
			now=a[i];
			num++;
		}
		if(num>=s){
			return true;
		}
	}
	return false;

}
int main()
{
	while(~scanf("%d %d",&l,&s)){
		if(l+s==0) break;
		for(int i=1;i<=l;i++) scanf("%d",&a[i]);
		sort(a+1,a+1+l);
		int ll=1,r=a[l]-a[1];
		while(ll<r){
			int mid = (ll+r+1)>>1;
			if(check(mid)){
				ll=mid;
			}else{
				r=mid-1;
			}
		}
		printf("%d\n",ll);
	}
}

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值