zoukankan      html  css  js  c++  java
  • 【二分】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 0

    sample 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
    ",(l+r)/2);
        }
        return 0;
    }
    
  • 相关阅读:
    jmeter压测学习42-逻辑控制器之交替控制器
    jmeter压测学习41-逻辑控制器之吞吐量控制器
    jmeter压测学习40-逻辑控制器之事务控制器
    jmeter压测学习39-获取post请求x-www-form-urlencoded格式的数据
    jmeter压测学习38-通过Jython调用Python脚本
    对微信小程序的生命周期进行扩展 – Typescript 篇
    在微信小程序开发中使用Typescript
    TCP长连接和短连接 Python代码
    jQuery Ajax编程
    Django 网页中文显示u开头的乱码
  • 原文地址:https://www.cnblogs.com/NeilThang/p/9356620.html
Copyright © 2011-2022 走看看