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. timus 1982 Electrification Plan(最小生成树)

    Electrification Plan Time limit: 0.5 secondMemory limit: 64 MB Some country has n cities. The govern ...

  2. meta是什么意思?

    META标签,是HTML语言head区的一个辅助性标签.在几乎所有的page里,我们都可以看 到类似下面这段html代码: -------------------------------------- ...

  3. OC IOS屏幕分辨率

    CGRect screenRect=[UIScreenmainScreen].bounds; CGSize screenSize=screenRect.size; //屏幕分辨率 screenSize ...

  4. 使用Animation实现摄像机动画

    项目剧情模块分给了我做,其中很重要的一个功能就是摄像机旋转平移等操作,本来打算使用Camera Path这个插件制作的,但是鉴于项目Unity版本还停留在4.3,低于插件要求版本,另外编辑器做出来是交 ...

  5. 【转】vs2012 打包安装更改 setup.exe的图标

    还是老外的文章给力 I'm not aware of any way to change the icon BEFORE building the project so that once the C ...

  6. HTML5之Canvas绘图实例——饼状图

    实现饼状分布画图(如下):调试环境:Firefox

  7. 关闭Outlook时最小化

    公司用的是阿里邮箱,foxmail客户端总是把已读邮件又标记成未读,又赶上最近招聘,真是深受其烦.已经无法忍受了,决定换了它,重新用起最强客户端outlook. Outlook解决了foxmail的问 ...

  8. java file的一些方法

    file包下的一些方法:       File file = new File("d:\\", "tea.txt");         //文件名        ...

  9. Js数组去重复取唯一值

    function isBigEnough(element) { return element >= 10; } var filtered = [12, 5, 8, 130, 44].filter ...

  10. mysql 10进制与35进制之间的转换 注意Power处理bigint的问题

    35进制的目的是防止0和O造成的视觉误差 BEGIN    DECLARE m_StrHex35 VARCHAR(100); -- 返回35进制表示的结果  DECLARE m_Remainder B ...