Educational Codeforces Round 15_C. Cellular Network
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
题意:
让你给每一个城市找一个塔来覆盖,然后叫你求出最小的覆盖半径,城市和塔都在一条直线上
题解:
我们直接枚举每一个城市,然后二分找一个最近的塔来覆盖
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
typedef long long ll; const int N=1E5+;
int a[N],b[N]; void up(int &a,int b){if(a<b)a=b;} int main(){
int n,m,eda=,edb=;
scanf("%d%d",&n,&m);
F(i,,n)scanf("%d",a+i);
F(i,,m)scanf("%d",b+i);
F(i,,n)if(a[i]!=a[eda])a[++eda]=a[i];//去重
F(i,,m)if(b[i]!=b[edb])b[++edb]=b[i];//去重
int ans=;
F(i,,eda){
int pos=lower_bound(b+,b++edb,a[i])-b-;
int tp=INT_MAX;//找一个最近的塔来更新答案
if(pos>=)tp=min(tp,a[i]-b[pos]);
if(pos<edb)tp=min(tp,b[pos+]-a[i]);
up(ans,tp);
}
printf("%d\n",ans);
return ;
}
Educational Codeforces Round 15_C. Cellular Network的更多相关文章
- Educational Codeforces Round 15 Cellular Network
Cellular Network 题意: 给n个城市,m个加油站,要让m个加油站都覆盖n个城市,求最小的加油范围r是多少. 题解: 枚举每个城市,二分查找最近的加油站,每次更新答案即可,注意二分的时候 ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [Educational Codeforces Round 16]B. Optimal Point on a Line
[Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
- Educational Codeforces Round 6 C. Pearls in a Row
Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
- Educational Codeforces Round 9
Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
随机推荐
- fork()子进程与waitpid()
#!/usr/bin/perl use warnings; use strict; use POSIX ":sys_wait_h"; $SIG{CHLD} = sub{ my $p ...
- easyui datagrid 的排序问题
今日遇到一个datagrid排序问题,sortable,sorter函数都已设置,但是始终没有效果,无法在界面自定义排序.后来发现,需要设置remoteSort:false. 切记!!! remote ...
- 在CDlinux下编译安装无线网卡驱动
环境 主机:ThinkPadT440P 系统:CDlinux9.7.1 概述 准备利用CDlinux来破解周围的wifi密码来免费蹭网,由于笔记本是新买的,系统没有自带驱动,只能自己手动到网上下载.编 ...
- fidder https以及Fiddler抓取HTTPS协议
一.浅谈HTTPS 我们都知道HTTP并非是安全传输,在HTTPS基础上使用SSL协议进行加密构成的HTTPS协议是相对安全的.目前越来越多的企业选择使用HTTPS协议与用户进行通信,如百度.谷歌等. ...
- 如何阅读一本书([美] 莫提默·J. 艾德勒 / 查尔斯·范多伦 )
进入豆瓣读书 前言 2017年1月2日跟着熊猫书院开始了为期十月的阅读计划. 熊猫书院是一个微信公众号,但仅对熊猫书院学员开放.它是一个很好的读书产品,从入学申请.入学报到.班长 ...
- usaco 17.Jan 铜组T3
上午在打usaco月赛的铜组题,T1T2是用来秒杀的,然而T3卡了一上午,下面给出题面: 题意大概就是输入一个N*N的矩阵,矩阵中元素只有0与1两种状态,每次操作以左上角的点为矩阵中某一矩阵的左上方顶 ...
- linux卸载rpm包
先查找要卸载的rpm包:比如cpp: #rpm -qa | grep cpp #rpm -e cpp-2.333x.x 如果提示有依赖,执行: #rpm -e cpp-2222 --nodeps
- 关于IOS的Cocoapods相关问题
Cocoa Pods确实是一个方便的工具,特别是在敏捷开发多个项目的时候,一个工具重复使用,大量节约时间: 可以及时更新github上面的开源库代码,只要改动Podfile文件中对应的开源库的版本号即 ...
- 【转】别人家的孩子之《说说我的web前端之路,分享些前端的好书》
链接http://www.cnblogs.com/Darren_code/archive/2011/02/09/JavaScript.html 2011-10-31 22:56 by 聂微东 PS ...
- Java 泛型 泛型方法
Java 泛型 泛型方法 @author ixenos 泛型方法可以定义在普通类中,也可以定义在泛型类中 类型变量放在修饰符(如public static)后面,返回类型的前面 一个static方法无 ...