Educational Codeforces Round 15 C 二分
3 seconds
256 megabytes
standard input
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.
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.
Print minimal r so that each city will be covered by cellular network.
3 2
-2 2 4
-3 0
4
5 3
1 5 10 14 17
4 11 15
3
题意:给你n个城市的坐标和m个塔的坐标 (都在x轴上,非递减的给出) 塔的工作范围为半径为r的圆
问最小的r使得所有的城市都在塔的工作范围内。
题解:枚举每个城市 二分得到最近的塔的位置 取距离差值的max
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#define ll __int64
using namespace std;
int n,m;
int a[];
int b[];
int main()
{
scanf("%d %d",&n,&m);
for(int i=; i<n; i++)
scanf("%d",&a[i]);
for(int i=; i<m; i++)
scanf("%d",&b[i]);
int ans=;
for(int i=; i<n; i++)
{
int pos=lower_bound(b,b+m,a[i])-b;
if(pos==)
ans=max(ans,b[pos]-a[i]);
else if(pos==m)
ans=max(ans,a[i]-b[pos-]);
else
ans=max(ans,min(b[pos]-a[i],a[i]-b[pos-]));
}
cout<<ans<<endl;
return ;
}
Educational Codeforces Round 15 C 二分的更多相关文章
- Educational Codeforces Round 15 C. Cellular Network(二分)
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 15 A, B , C 暴力 , map , 二分
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 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 ...
- Codeforces Educational Codeforces Round 15 A. Maximum Increase
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 15 (A - E)
比赛链接:http://codeforces.com/contest/702 A. Maximum Increase A题求连续最长上升自序列. [暴力题] for一遍,前后比较就行了. #inclu ...
- Educational Codeforces Round 61 D 二分 + 线段树
https://codeforces.com/contest/1132/problem/D 二分 + 线段树(弃用结构体型线段树) 题意 有n台电脑,只有一个充电器,每台电脑一开始有a[i]电量,每秒 ...
- Educational Codeforces Round 15 A dp
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 15 Cellular Network
Cellular Network 题意: 给n个城市,m个加油站,要让m个加油站都覆盖n个城市,求最小的加油范围r是多少. 题解: 枚举每个城市,二分查找最近的加油站,每次更新答案即可,注意二分的时候 ...
- Educational Codeforces Round 15 Powers of Two
Powers of Two 题意: 让求ai+aj=2的x次幂的数有几对,且i < j. 题解: 首先要知道,排完序对答案是没有影响的,比如样例7 1一对,和1 7一对是样的,所以就可以排序之后 ...
随机推荐
- 部分SIM卡被曝存安全漏洞:7.5亿部手机受牵连
7月22日消息,据国外媒体报道,一安全研究人员发现部分移动SIM卡所使用的加密方式存在一个安全漏洞,可能会导致手机被黑客远程控制. DES数据加密标准的SIM卡——DES是一种较旧的标准,目前正被部分 ...
- Arithmetic Progressions
题目大意: 求出满足条件A的等差数列: A:长度为N(N<=25),每个元素都能表示成 两个数p,q的平方和(0<=p,q<=m<=250): 解题过程: 1.处理出所有的能拆 ...
- JavaScript 自定义事件
//自定义事件 function Event() { var handles = []; //绑定事件 this.addHandle=function(fn) { handles.push(fn); ...
- js用正则表达式控制价格输入
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...
- localStorage
length:唯一的属性,只读,用来获取storage内的键值对数量. key:根据index获取storage的键名 getItem:根据key获取storage内的对应value setItem: ...
- json数组,随便测试
Pid := '1001411225514227,926792194654225'; json := SA([]); json.AsArray.Add(SO(pid)); ShowMessage( j ...
- HDU 3377 插头dp
题目大意: 从左上角走到右下角,每个点之多经过一次,取到所有路径上经过点的权值,求最大的权值之和,这里走到右下角就算停止了 这里有个思路是转化成熟悉的回路问题 在上方和右方最外围定义一圈权值为0 , ...
- powershell加win的dns服务器,解决网站负载均衡问题
用我发明的powershell填坑法,加windows的dns服务器.从调整dns服务器解析ip时间段的角度,解决网站负载均衡问题. ------------------------win2012r2 ...
- android 禁止viewPager 滑动
public class ContainerViewPager extends MyViewPager { public ContainerViewPager(Context context, Att ...
- MySQL v5.1.72 + v5.6.19
MYSQL是一个多线程的,结构化查询语言(SQL)数据库服务器.SQL 在世界上是最流行的数据库语言.MySQL 的执行性能非常高,运行速度非常快,并非常容易使用.是一个非常捧的数据库. MySQL ...