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一对是样的,所以就可以排序之后 ...
随机推荐
- display:flex
元素在x方向走,元素y不一样[高度].可以用对齐.align-items. align-self 自身调节元素在x方向走,元素在x方向距离.justify-content . 元素在x方向走,x方 ...
- JAVA中StringBuffer类常用方法详解
String是不变类,用String修改字符串会新建一个String对象,如果频繁的修改,将会产生很多的String对象,开销很大.因此java提供了一个StringBuffer类,这个类在修改字符串 ...
- mysql数据库 安装 (原创)
1.首先下载mysql 数据库,我安装的是mysql5.1版本,直接安装就行,但是如果以后你想在数据库里显示中文的话,要把字符集设置为gb2312 2.配置数据源odbc. mysql-connec ...
- jQuery 其他操作
1. 样式操作 1.1 获取 class 和设置 class : class 是元素的一个属性, 所以获取 class 和设置 class 都可以使用 attr() 方法来完成. 1.2 追加样式: ...
- 简单的两数之和再次乱入<< Add Two Numbers >>
请看题目描述: You are given two linked lists representing two non-negative numbers. The digits are stored ...
- scanf和scanfs的区别
scanf()函数是标准C中提供的标准输入函数,用以用户输入数据 scanf_s()函数是Microsoft公司VS开发工具提供的一个功能相同的安全标准输入函数,从vc++2005开始,VS系统提供了 ...
- linux下的文件权限管理
权限管理有两个层面 第一层区分用户:文件属主(u), 组用户(g), 其它(o) 第二层区分权限:读(r),写(w),可执行(x) 这两个层次构成文件权限管理的二维结构 u g ...
- S50非接触式IC卡性能简介(M1)
一.主要指标 分为16个扇区,每个扇区为4块,每块16个字节,以块为存取单位: 每个扇区有独立的一组密码及访问控制: 每张卡有唯一序列号,为32位: 具有防冲突机制,支持多卡操作: 无电源,自带天线, ...
- php大力力 [031节] php设计系统后台菜单和样式设计
php大力力 [031节] php设计系统后台菜单和样式设计 耗掉我一整夜的时间,把后台html设计了一个,对于我这样的html白痴,实属不容易啊. 留下一点点网上查找的网页知识: 索马里论坛群发简介 ...
- 黑马程序员——【Java基础】——Java概述
---------- android培训.java培训.期待与您交流! ---------- 一.Java语言概述及三大技术架构 1.Java语言概述 Java是SUN公司于1995年推出的一种面向I ...