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 rfrom 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
题目链接:C. Cellular Network
让每一个城市都可以被供给,也就是说每一个发电站的距离向左右延伸后要把城市最小~最大范围全部覆盖到,想了一会儿感觉是找每一个城市的最近供给站的距离,然后取最大值作为标准,然后进行二分……,然后怎么找这个最近的供给站呢?还是二分……,找的时候注意边界就可以了
代码:
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define MM(x,y) memset(x,y,sizeof(x))
#define LC(x) (x<<1)
#define RC(x) ((x<<1)+1)
#define MID(x,y) ((x+y)>>1)
typedef pair<int,int> pii;
typedef long long LL;
const double PI=acos(-1.0);
const int N=100010;
int n,m;
int c[N];
int d[N];
int vis[N];
LL min_dis[N];
inline LL ABS(const LL &a)
{
return a>0?a:-a;
}
int main(void)
{
int i,j,k;
while (~scanf("%d%d",&n,&m))
{
for (i=0; i<n; ++i)
{
scanf("%d",&c[i]);
}
for (i=0; i<m; ++i)
{
scanf("%d",&d[i]);
}
LL dx=0;
for (i=0; i<n; ++i)
{
int l=lower_bound(d,d+m,c[i])-d;
int r=upper_bound(d,d+m,c[i])-d-1;
if(l>=m)
l=m-1;
if(r>=m)
r=m-1;
if(r<0)
r=0;
min_dis[i]=min(ABS((LL)c[i]-d[l]),ABS((LL)c[i]-d[r]));
if(min_dis[i]>dx)
dx=min_dis[i];
}
int nm=n+m;
LL l=0,r=2LL*1e9,mid,ans;
while (l<=r)
{
mid=(l+r)>>1;
if(mid>=dx)
{
r=mid-1;
ans=mid;
}
else
l=mid+1;
}
printf("%I64d\n",ans);
}
return 0;
}
Educational Codeforces Round 15 C. 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 ...
- Educational Codeforces Round 15 Cellular Network
Cellular Network 题意: 给n个城市,m个加油站,要让m个加油站都覆盖n个城市,求最小的加油范围r是多少. 题解: 枚举每个城市,二分查找最近的加油站,每次更新答案即可,注意二分的时候 ...
- Educational Codeforces Round 15 C 二分
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 ...
- Educational Codeforces Round 15 (A - E)
比赛链接:http://codeforces.com/contest/702 A. Maximum Increase A题求连续最长上升自序列. [暴力题] for一遍,前后比较就行了. #inclu ...
- 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 21 D.Array Division(二分)
D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process 题目连接: http://www.codeforces.com/contest/660/problem/C Description You are given an a ...
- Educational Codeforces Round 26 F. Prefix Sums 二分,组合数
题目链接:http://codeforces.com/contest/837/problem/F 题意:如题QAQ 解法:参考题解博客:http://www.cnblogs.com/FxxL/p/72 ...
随机推荐
- JSTL分类查询
index.jsp <%@ page language="java" import="java.util.*" pageEncoding="UT ...
- 消息队列入门(三)JMS标准及实现
>>消息中间件 消息中间件即Message-oriented middleware(MOM),消息中间件利用高效可靠的消息传递机制进行平台无关的数据交流,并基于数据通信来进行分布式系统的集 ...
- PHP CI框架学习笔记-分页实现程序
视图html <div id="body"> <form action="/index.php/search/index/" method= ...
- Office Word 2013发布带数学公式的博客
今日在自学冈萨雷斯的<数字图像处理>一书,想做笔记来记录,并分享一些MATLAB代码,又加上刚刚注册博客园的账户,便想着如何能够较为方便的来书写博客.本文主要涉及到的问题有: 如何用wor ...
- C++的那些事:类的拷贝控制
1,什么是类的拷贝控制 当我们定义一个类的时候,为了让我们定义的类类型像内置类型(char,int,double等)一样好用,我们通常需要考下面几件事: Q1:用这个类的对象去初始化另一个同类型的对象 ...
- loj 1017(dp)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=25843 思路:我们可以发现题目与点的X坐标没有关系,于是可以直接对 ...
- ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component解决
第一:先确定一下开发流程是否正确 1.写好servlet组件类 2.写好web.xml文件--向服务器介绍组件 3.发布--就是拷贝 注意:要拷贝包结构,不要只拷贝组件类文件 另外,拷贝的是.clas ...
- Scala中的Implicit(隐式转换,隐式参数,隐式类)
文章来自:http://www.cnblogs.com/hark0623/p/4196452.html 转发请注明 代码如下: /** * 隐式转换 隐式参数 隐式类 */ //隐式转换 class ...
- Win7-64bit系统下安装mysql的ODBC驱动
安装过mysql数据库后,有些软件在调用mysql数据库时不会直接调用,需要安装mysql数据库的ODBC驱动,再来调用.这里就介绍下,如何在win7系统下安装mysql的ODBC驱动. Win7系统 ...
- ie9始终提示文档预览需要最新版本的Flash Player支持的解决方法:
下载Flash Player 最新版 百度 搜索 第二步: