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. android中ListView_SimpleAdapter

    1.首先看下main_activity.xml.其实里面就放了一个ListView. <LinearLayout xmlns:android="http://schemas.andro ...

  2. P168 实战练习(权限修饰符)

    创建Game类,运行代码如下: package org.hanqi.pn0120; public class Game { private String name; private String ca ...

  3. 【转】IOS静态库a文件制作流程

    原文网址:http://www.jianshu.com/p/3439598ea61f 1.新建Cocoa Touch Static Library工程 新建工程 2.Xcode的参数设置 " ...

  4. RandomAccessFile

    RandomAccessFile是用来访问那些保存数据记录的文件的,你就可以用seek( )方法来访问记录,并进行读写了.这些记录的大小不必相同:但是其大小和位置必须是可知的.但是该类仅限于操作文件

  5. T4 Templates

    T4 Templates and the Entity Framework https://msdn.microsoft.com/en-us/data/gg558520.aspx EF Designe ...

  6. C#字符补位

    C#字符补位 .byte类型的字符,用5位2进制数表示,右对齐,不足5位,前面补零. byte b; Convert.ToString(b, ).PadLeft(, ') .byte类型的字符,用2位 ...

  7. jquery事件切换hover/toggle

    1.hover([over,]out) 一个模仿悬停事件(鼠标移动到一个对象上面及移出这个对象)的方法.这是一个自定义的方法,它为频繁使用的任务提供了一种“保持在其中”的状态. 当鼠标移动到一个匹配的 ...

  8. disruptor - Concurrent Programming Framework 并发编程框架

    disruptor发布了Java的2.0版本(.Net版本见这里),disruptor是一个高性能的异步处理框架,或者可以认为是最快的消息框架(轻量的JMS),也可以认为是一个观察者模式实现,或者事件 ...

  9. MySQL 利用SQL线程对Binlog操作(转)

    背景: 对于MySQL的binlog的查看都是用其自带的工具mysqlbinlog进行操作的,其实还有另一个方法来操作binlog,就是Replication中的SQL线程去操作binlog,其实bi ...

  10. Android 文件的选择

    Android 文件的选择 打开文件选择器 private void showFileChooser() { Intent intent = new Intent(Intent.ACTION_GET_ ...