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 — 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 31 5 10 14 174 11 15

output

3

这题好迷的

就是对于每个a[i],求出min{ |a[i]-b[j]| }

然后再在n个数中取个最大值输出

简直就是模拟嘛

这里求min我又用了二分(应该三分也可以,吧。毕竟有个abs就是单峰的)

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<algorithm>
 6 #include<cmath>
 7 #include<ctime>
 8 #define LL long long
 9 #define inf 0x7ffffff
10 #define pa pair<int,int>
11 #define pi 3.1415926535897932384626433832795028841971
12 using namespace std;
13 inline LL read()
14 {
15     LL x=0,f=1;char ch=getchar();
16     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
17     while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
18     return x*f;
19 }
20 inline void write(LL a)
21 {
22     if (a<0){printf("-");a=-a;}
23     if (a>=10)write(a/10);
24     putchar(a%10+‘0‘);
25 }
26 inline void writeln(LL a){write(a);printf("\n");}
27 int n,m,ans;
28 int a[100010];
29 int b[100010];
30 int dist[100010];
31 inline int bsearch(int l,int r,int dat)
32 {
33     int ans=0;
34     while (l<=r)
35     {
36         int mid=(l+r)>>1;
37         if (b[mid]<dat){ans=mid;l=mid+1;}
38         else r=mid-1;
39     }
40     return ans;
41 }
42 int main()
43 {
44     n=read();m=read();
45     for(int i=1;i<=n;i++)a[i]=read();
46     sort(a+1,a+n+1);
47     for (int i=1;i<=m;i++)b[i]=read();
48     sort(b+1,b+m+1);
49     int now=1;
50     for (int i=1;i<=n;i++)
51     {
52         int fnd=bsearch(1,m,a[i]);
53         if (fnd==0)fnd++;dist[i]=abs(b[fnd]-a[i]);
54         if (fnd!=m)dist[i]=min(abs(b[fnd]-a[i]),abs(b[fnd+1]-a[i]));
55         ans=max(ans,dist[i]);
56     }
57     printf("%d\n",ans);
58 }

cf702D

时间: 2024-10-18 05:30:05

cf702C Cellular Network的相关文章

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

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

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

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 ](只有最左或最右灯塔时

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

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

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