zoukankan      html  css  js  c++  java
  • codeforces 702C C. Cellular Network(水题)

    题目链接:

    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

    题意:

    给每个城市找一个供给,问最小的半径是多少;

    思路:

    二分;

    AC代码:

    /************************************************ 
    ┆  ┏┓   ┏┓ ┆    
    ┆┏┛┻━━━┛┻┓ ┆ 
    ┆┃       ┃ ┆ 
    ┆┃   ━   ┃ ┆ 
    ┆┃ ┳┛ ┗┳ ┃ ┆ 
    ┆┃       ┃ ┆  
    ┆┃   ┻   ┃ ┆ 
    ┆┗━┓    ┏━┛ ┆ 
    ┆  ┃    ┃  ┆       
    ┆  ┃    ┗━━━┓ ┆ 
    ┆  ┃  AC代马   ┣┓┆ 
    ┆  ┃           ┏┛┆ 
    ┆  ┗┓┓┏━┳┓┏┛ ┆ 
    ┆   ┃┫┫ ┃┫┫ ┆ 
    ┆   ┗┻┛ ┗┻┛ ┆       
    ************************************************ */  
    
    
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <bits/stdc++.h>
    #include <stack>
    
    using namespace std;
    
    #define For(i,j,n) for(int i=j;i<=n;i++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
    
    typedef  long long LL;
    
    template<class T> void read(T&num) {
        char CH; bool F=false;
        for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
        for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
        F && (num=-num);
    }
    int stk[70], tp;
    template<class T> inline void print(T p) {
        if(!p) { puts("0"); return; }
        while(p) stk[++ tp] = p%10, p/=10;
        while(tp) putchar(stk[tp--] + '0');
        putchar('
    ');
    }
    
    const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const int inf=1e9;
    const int N=1e5+10;
    const int maxn=(1<<8);
    const double eps=1e-8;
    
    int a[N],b[N],n,m;
    
    int check2(int x)
    {
        int l=1,r=m;
        while(l<=r)
        {
            int mid=(l+r)>>1;
            if(b[mid]>x)r=mid-1;
            else l=mid+1;
        }
        if(r==0)r=1;
        return r;
    }
    int check1(int x)
    {
        int l=1,r=m;
        while(l<=r)
        {
            int mid=(l+r)>>1;
            if(b[mid]<x)l=mid+1;
            else r=mid-1;
        }
        if(l>m)l=m;
        return l;
    }
    
    int main()
    {       
            read(n);read(m);
            For(i,1,n)read(a[i]);
            For(i,1,m)read(b[i]);
            int ans=0;
            For(i,1,n)
            {
    
                int l=check1(a[i]);
                int r=check2(a[i]);
                //cout<<l<<" "<<r<<endl;
                int temp=min(abs(b[l]-a[i]),abs(b[r]-a[i]));
                ans=max(ans,temp);
    
            }
            cout<<ans<<endl;
    
            return 0;
    }
    

      

  • 相关阅读:
    共享无法访问问题,通过ip地址或者主机名无法访问目的主机
    开机系统更新,一直停在?%处,无法进入系统
    win7电脑访问内网地址报错0x800704cf,0x80070035解决方法
    电脑共享--问题汇总
    win10域账户用户时间无法和域服务器同步
    卸载WPS后,原office出现各种问题,报错,图标混乱
    局域网新装电脑主机网络断断连连解决方案
    win10主机无法进入本地共享,“没有权限”
    win10安装部分软件报错“应用程序无法启动,应用程序并行配置不正确,或使用命令行sxstrace.exe”
    【日常修机】打印机故障维护
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5720281.html
Copyright © 2011-2022 走看看