CodeForce-702C Cellular Network(查找)

Cellular Network

CodeForces - 702C

给定 n (城市数量) 和 m (灯塔数量);

给定 a1~an 城市坐标;

给定 b1~bm 灯塔坐标;

求出灯塔照亮的最小半径 r ,使得所有城市都能被照亮。

Input

3 2-2 2 4-3 0

Output

4

Input

5 31 5 10 14 174 11 15

Output

3

题解:

首先对于每个城市 a[ i ],找到离它最近的左右两个灯塔  b [ x ] , b [ x-1 ](只有最左或最右灯塔时 特判),然后比较这两个灯塔与该城市的距离,取最小值 F [ i ] 。

对于所有的城市,要求出灯塔最小半径,要在 F [ 1 ] ~ F [ n ] 中求最大值。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;

typedef long long ll;
const int N=1e5+50;
ll a[N];
ll b[N];
int n,m;

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%lld",&a[i]);
    for(int i=0;i<m;i++)
        scanf("%lld",&b[i]);
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        int x=lower_bound(b,b+m,a[i])-b;
        ll temp;
        if(x==0)//只有最左边灯塔
            temp=abs(a[i]-b[0]);
        else if(x==m)//只有最右边灯塔
            temp=abs(a[i]-b[m-1]);
        else //左右灯塔取最近之一
            temp=min(abs(a[i]-b[x]),abs(a[i]-b[x-1]));
        ans=max(ans,temp);//在各个城市与灯塔的距离中保留最大值比较出 r
    }
    cout<<ans<<endl;
    return 0;
}
时间: 2024-10-08 08:15:57

CodeForce-702C Cellular Network(查找)的相关文章

codeforce 702C Cellular Network 二分答案

http://codeforces.com/contest/702 题意:n个村庄,m个机站,问机站最短半径覆盖完所有村庄 思路:直接二分答案 二分太弱,调了半天..... 1 // #pragma comment(linker, "/STACK:102c000000,102c000000") 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #include <s

CodeForces - 702C Cellular Network

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 ci

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

cf702C 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

Codeforces Educational Codeforces Round 15 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

Educational Codeforces Round 15_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

UVA 1456 六 Cellular Network

Cellular Network Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 1456 A cellular network is a radio network made up of a number of cells each served by a base station located in the cell. The base sta

UVALive 4731 Cellular Network

分析: 状态是一些有序的集合,这些集合互不相交,并集为所有区域.显然枚举集合元素是哪些是无法承受的, 写出期望的计算式,会发现一个贪心,当每个集合的大小确定了以后,概率大的优先访问是最优的.容易证明,也符合直觉. 因此先对u从大到小排序.定义状态f[i][j]表示从j开始往后分i组的最小期望. 转移是枚举划分k,则有f[i][j] = min{f[i-1][k]+(k-j)*(u[n]-u[j-1])},k>j 边界f[1][j] = (n-j+1)*(u[n]-u[j-1]) #include

UVA - 1456 Cellular Network

题目大意: 手机在蜂窝网络中的定位是一个基本问题.假设蜂窝网络已经得知手机处于c1, c2,-,cn这些区域中的一个,最简单的方法是同时在这些区域中寻找手机.但这样做很浪费带宽.由于蜂窝网络中可以得知手机在这不同区域中的概率,因此一个折中的方法就是把这些区域分成w组,然后依次访问.比如,已知手机可能位于5个区域中,概率分别为0.3.0.05.0.1.0.3和0.25,w=2,则一种方法是先同时访问{c1,c2,c3},再同时访问{c4,c5},访问区域数的数学期望为3*(0.3+0.05+0.1