cf702C 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 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
这题好迷的
就是对于每个a[i],求出min{ |a[i]-b[j]| }
然后再在n个数中取个最大值输出
简直就是模拟嘛
这里求min我又用了二分(应该三分也可以,吧。毕竟有个abs就是单峰的)
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void write(LL a)
{
if (a<){printf("-");a=-a;}
if (a>=)write(a/);
putchar(a%+'');
}
inline void writeln(LL a){write(a);printf("\n");}
int n,m,ans;
int a[];
int b[];
int dist[];
inline int bsearch(int l,int r,int dat)
{
int ans=;
while (l<=r)
{
int mid=(l+r)>>;
if (b[mid]<dat){ans=mid;l=mid+;}
else r=mid-;
}
return ans;
}
int main()
{
n=read();m=read();
for(int i=;i<=n;i++)a[i]=read();
sort(a+,a+n+);
for (int i=;i<=m;i++)b[i]=read();
sort(b+,b+m+);
int now=;
for (int i=;i<=n;i++)
{
int fnd=bsearch(,m,a[i]);
if (fnd==)fnd++;dist[i]=abs(b[fnd]-a[i]);
if (fnd!=m)dist[i]=min(abs(b[fnd]-a[i]),abs(b[fnd+]-a[i]));
ans=max(ans,dist[i]);
}
printf("%d\n",ans);
}
cf702D
cf702C Cellular Network的更多相关文章
- Educational Codeforces Round 15 C. Cellular Network(二分)
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- UVA 1456 六 Cellular Network
Cellular Network Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit S ...
- Educational Codeforces Round 15 Cellular Network
Cellular Network 题意: 给n个城市,m个加油站,要让m个加油站都覆盖n个城市,求最小的加油范围r是多少. 题解: 枚举每个城市,二分查找最近的加油站,每次更新答案即可,注意二分的时候 ...
- 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 ...
- 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 702C Cellular Network 2016-10-15 18:19 104人阅读 评论(0) 收藏
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- codeforces 702C C. Cellular Network(水题)
题目链接: C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input st ...
- CodeForce-702C Cellular Network(查找)
Cellular Network CodeForces - 702C 给定 n (城市数量) 和 m (灯塔数量): 给定 a1~an 城市坐标: 给定 b1~bm 灯塔坐标: 求出灯塔照亮的最小半径 ...
- Codeforces 702C Cellular Network
题目:这里 题意:一条数轴上,有n个城市和m个塔,分别给出城市的位置和塔的位置,每个塔有个覆盖范围,问能将所有城市都覆盖的塔的最小范围是多少,一个城市只要被至少一个塔 覆盖就行. 可以利用贪心的思想模 ...
随机推荐
- Node.js + Express + Mongodb 开发搭建个人网站(一)
一.Node + Express环境搭建 0.去Node官网下载安装node,如果安装了 npm 和 node的话 那么就 安装 全局的 express,-g全局安装 npm install expr ...
- native跟volatile
native是告知编译器 该方法是其他语言实现的 比如C 呵呵 private native void CoutSea();没有方法实现部分的 volatile是Java语言的关键字,用在变量的声明中 ...
- myEclipse修改deploy location
- 在treeview外加一个滚动条的实现
前台代码: <div style="overflow:auto;width:190px;height:280px;border:1px solid #336699;padding-le ...
- linux常用编辑器
管理员在进行系统操作的时候,不可避免地会对文本进行修改,如进行各种服务程序配置文件的改动,使程序对用户提供不同的服务效果.在本章我们向大家介绍Linux上常见的编辑器ed.vi.emacs,同时以vi ...
- OC - 25.CAKeyframeAnimation
概述 简介 CAKeyframeAnimation又称关键帧动画 CAKeyframeAnimation是抽象类CAPropertyAnimation的子类,可以直接使用 通过values与path两 ...
- Java study 2:The note of studying Socket which based TCP
TCP concept: 传输控制协议(Transmission Control Protocol, TCP)是一种面向连接(连接导向)的.可靠的.基于字节流的运输层(Transport layer) ...
- 浅析CSS中的haslayout
作为一名web开发人员,最大的希望不是自己的水平有多高,而是希望浏览器厂家能够统一标准,相信任何一个只要是接触过web程序开发的人员都有那样的感受,就是浏览器之间的兼容性问题总是让我们的工作平添诸多的 ...
- 原生JS判断密码强弱
前些天工作中有这个需求,自己手写了相关的JS代码,第一种方法是通过ASCII 码判断密码类型,完成用户注册时判断用户输入密码的强度,分强.弱.中三等级,它可以根据用户输入的密码显示对应的密码强弱等级, ...
- [LeetCode OJ] Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...