zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 15 C 二分

    C. Cellular Network
    time limit per test
    3 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given n points on the straight line — the positions (x-coordinates) of the cities and m points on the same line — the positions (x-coordinates) of the cellular towers. All towers work in the same way — they provide cellular network for all cities, which are located at the distance which is no more than r from this tower.

    Your task is to find minimal r that each city has been provided by cellular network, i.e. for each city there is at least one cellular tower at the distance which is no more than r.

    If r = 0 then a tower provides cellular network only for the point where it is located. One tower can provide cellular network for any number of cities, but all these cities must be at the distance which is no more than r from this tower.

    Input

    The first line contains two positive integers n and m (1 ≤ n, m ≤ 105) — the number of cities and the number of cellular towers.

    The second line contains a sequence of n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the coordinates of cities. It is allowed that there are any number of cities in the same point. All coordinates ai are given in non-decreasing order.

    The third line contains a sequence of m integers b1, b2, ..., bm ( - 109 ≤ bj ≤ 109) — the coordinates of cellular towers. It is allowed that there are any number of towers in the same point. All coordinates bj are given in non-decreasing order.

    Output

    Print minimal r so that each city will be covered by cellular network.

    Examples
    input
    3 2
    -2 2 4
    -3 0
    output
    4
    input
    5 3
    1 5 10 14 17
    4 11 15
    output
    3

     题意:给你n个城市的坐标和m个塔的坐标 (都在x轴上,非递减的给出)  塔的工作范围为半径为r的圆

    问最小的r使得所有的城市都在塔的工作范围内。

     题解:枚举每个城市 二分得到最近的塔的位置 取距离差值的max

     1 /******************************
     2 code by drizzle
     3 blog: www.cnblogs.com/hsd-/
     4 ^ ^    ^ ^
     5  O      O
     6 ******************************/
     7 //#include<bits/stdc++.h>
     8 #include<iostream>
     9 #include<cstring>
    10 #include<cstdio>
    11 #include<map>
    12 #include<algorithm>
    13 #include<queue>
    14 #define ll __int64
    15 using namespace std;
    16 int n,m;
    17 int a[100005];
    18 int b[100005];
    19 int main()
    20 {
    21     scanf("%d %d",&n,&m);
    22     for(int i=0; i<n; i++)
    23         scanf("%d",&a[i]);
    24     for(int i=0; i<m; i++)
    25         scanf("%d",&b[i]);
    26     int ans=0;
    27     for(int i=0; i<n; i++)
    28     {
    29         int pos=lower_bound(b,b+m,a[i])-b;
    30         if(pos==0)
    31             ans=max(ans,b[pos]-a[i]);
    32         else if(pos==m)
    33             ans=max(ans,a[i]-b[pos-1]);
    34         else
    35             ans=max(ans,min(b[pos]-a[i],a[i]-b[pos-1]));
    36     }
    37     cout<<ans<<endl;
    38     return 0;
    39 }
  • 相关阅读:
    题解 P1587 【[NOI2016]循环之美】
    PKUSC2019颓废记
    使用ImageIO.write上传二维码文件时候,提示系统找不到指定路径
    rt.jar包添加源文件只需要关联到已安装对应jdk目录下source.zip源码文件即可
    Kali Linux安装中文输入法
    性能测试(一)——理发店模型
    瑜伽,不仅仅是瑜伽,敬艾扬格大师
    为什么想做测试,我的测试开端
    责任链模式-Chain of responsibility
    后缀数组-基础
  • 原文地址:https://www.cnblogs.com/hsd-/p/5748630.html
Copyright © 2011-2022 走看看