Cellular Network

题意:

给n个城市,m个加油站,要让m个加油站都覆盖n个城市,求最小的加油范围r是多少。

题解:

枚举每个城市,二分查找最近的加油站,每次更新答案即可,注意二分的时候不要越界oil数组,上下界都不要越。还有,int坑死人,以后绝对全用long long!!!

代码:

#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int INF=0x3f3f3f3f;
const ll LINF=0x3f3f3f3f3f3f3f3f;
#define PU puts("");
#define PI(A) cout<<A<<endl
#define SI(N) cin>>N
#define SII(N,M) cin>>N>>M
#define cle(a,val) memset(a,(val),sizeof(a))
#define rep(i,b) for(int i=0;i<(b);i++)
#define Rep(i,a,b) for(int i=(a);i<=(b);i++)
#define reRep(i,a,b) for(int i=(a);i>=(b);i--)
#define dbg(x) cout <<#x<<" = "<<x<<endl
#define PIar(a,n) rep(i,n)cout<<a[i]<<" ";cout<<endl;
#define PIarr(a,n,m) rep(aa,n){rep(bb, m)cout<<a[aa][bb]<<" ";cout<<endl;}
const double EPS= 1e-9 ; /* ///////////////////////// C o d i n g S p a c e ///////////////////////// */ const int MAXN= 100000 + 9 ; ll city[MAXN],oil[MAXN];
ll N,M; int main()
{
iostream::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
while(SII(N,M))
{
rep(i,N)SI(city[i]);
rep(i,M)SI(oil[i]);
ll ans=0;
rep(i,N)
{
ll t=lower_bound(oil,oil+M,city[i])-oil;
ll d=LINF;
if (t<M)
d=abs(oil[t]-city[i]);
ll d2=LINF;
if (t-1>=0)
d2=abs(oil[t-1]-city[i]);
ans=max(ans,min(d,d2));
}
PI(ans);
}
return 0;
}

Educational Codeforces Round 15 Cellular Network的更多相关文章

  1. Educational Codeforces Round 15_C. Cellular Network

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  2. 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 ...

  3. Educational Codeforces Round 15 C. Cellular Network(二分)

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  4. Educational Codeforces Round 15 C 二分

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  5. Educational Codeforces Round 15 (A - E)

    比赛链接:http://codeforces.com/contest/702 A. Maximum Increase A题求连续最长上升自序列. [暴力题] for一遍,前后比较就行了. #inclu ...

  6. 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 ...

  7. 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 ...

  8. Educational Codeforces Round 15 A dp

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. Codeforces Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph

    E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 me ...

随机推荐

  1. 黑马程序员——JAVA基础之List集合

    ------- android培训.java培训.期待与您交流! ---------- Collection : |--List:元素是有序的,元素可以重复.因为该集合体系有索引.         | ...

  2. EXT3_DX_ADD_ENTRY: DIRECTORY INDEX FULL!

    inode问题故障1例故障关键字:ext3_dx_add_entry: Directory index full! 线上业务的一台服务器无缘无故突然挂了让机房帮忙连接显示器后发现报错 http://i ...

  3. supervisor运行golang守护进程

    最近在鼓捣golang守护进程的实现,无意发现了supervisor这个有意思的东西.supervisor是一个unix的系统进程管理软件,可以用它来管理apache.nginx等服务,若服务挂了可以 ...

  4. MiniCRT 64位 linux 系统移植记录:64位gcc的几点注意

    32位未修改源码与修改版的代码下载: git clone git@github.com:youzhonghui/MiniCRT.git MiniCRT 64位 linux 系统移植记录 MiniCRT ...

  5. ORA-01089 数据库无法正常关闭

    今天在做SOA几个数据库的重启操作,其中一个数据库在关闭过程中一直处于HANG住状态,十几分钟没有任何进展,具体操作过程如下: 一:当时的情景 SQL> shutdown immediate - ...

  6. data pump (数据抽取)测试

    背景介绍>利用db_link直接pump抽取,减少转储文件集. 前提:   授权>  grant create public database link,create database l ...

  7. InnoDB Double write

    记得刚开始看InnoDB文档的时候,Double Write一节(其实只有一小段)就让我很困惑.无奈当时内力太浅,纠缠了很久也没弄明白.时隔几个月,重新来整理一下. 涉及到的概念:Buffer Poo ...

  8. 学习tornado:安全

    http://blog.csdn.net/siddontang/article/details/18053915

  9. JSP 相关试题(五)

    Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE MicrosoftInternetExplorer4 /* Style Definiti ...

  10. XMLHttpRequest 对象

    XMLHttpRequest 对象 XML XSLTXML 解析器XMLHttpRequest 对象用于在后台与服务器交换数据. 什么是 XMLHttpRequest 对象? XMLHttpReque ...