• 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 }
  • 相关阅读:
    HDU 1978 How many ways
    hdu 1966 Pie
    hdu 1966 Pie
    HDU 1896 Stones
    HDU 1896 Stones
    hdu 1278 逃离迷宫
    hdu 1278 逃离迷宫
    HDU 2548 A strange lift
    HDU 2548 A strange lift
    PHP 错误与异常 笔记与总结(10)错误处理器测试
  • 原文地址:https://www.cnblogs.com/hsd-/p/5748630.html
Copyright © 2020-2023  润新知