Educational Codeforces Round 15 Cellular Network
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的更多相关文章
- Educational Codeforces Round 15_C. Cellular Network
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- 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 C. Cellular Network(二分)
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- 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 - E)
比赛链接:http://codeforces.com/contest/702 A. Maximum Increase A题求连续最长上升自序列. [暴力题] for一遍,前后比较就行了. #inclu ...
- 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 ...
- 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 15 A dp
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 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 ...
随机推荐
- 设置Eclipse支持C++ 11
设置Eclipse支持C++ 11 两个步骤: 项目 > Properties > C/C++ Build > Setting > GCC C++ Compiler > ...
- 1-3-1 关于API
主要内容:API函数及其相关内容的介绍.Windows编程相关基础知识介绍 1.API函数的概念 <1>API(Application Programming interface),即应用 ...
- PPT图片快速编辑技巧
修改*.ppt或*.pptx的后缀名为zip 例如:demo.pptx修改为demo.zip 修改为, 使用压缩软件打开此压缩包, 一般图片资源都会存放在ppt/media下 找到你所要修改的图片,然 ...
- VMware虚拟机打开不了操作系统的解决方案
1. 当你的VMware虚拟机出现下面这种情况的时候 解决方案:找到此VM安装的文件夹.在此文件夹下,将名字以“.lck ”结尾的文件夹全部重命名,重命名的名字随意好了.然后再到VMWARE里启动你的 ...
- (转) Reinforcement Learning for Profit
Reinforcement Learning for Profit July 17, 2016 Is RL being used in revenue generating systems today ...
- CentOS下添加新硬盘
1.查看新硬盘 #fdisk –l 新添加的硬盘的编号为/dev/sdb 2.硬盘分区 1)进入fdisk模式 #/sbin/fdisk /dev/sdb 2)输入n进行分 ...
- linux服务之smtp
实现这个协议的软件太多,有sendmail,postfix等.不像snmp,基本上是net-snmp一统天下, yum install nc nc用来取代telnet 这里我们希望让大家知道网络协议中 ...
- P1003 越野跑【tyvj】
/*=========================================================== P1003 越野跑 描述 Description 为了能在下一次跑步比赛中有 ...
- Nancy 简单学习
1. 环境 vs2010 , nancy 2. 需要测试的功能 1. 输出 页面输出简单文本 2. 输出json 数据 3. 操作 1. 创建asp.net 空项目 2. 添加引用Nancy库 使用n ...
- MongoDB权限管理之用户名和密码的操作
MongoDB默认是不需要输入用户名和密码,客户就可以登录的.但是出于安全性的考虑,我们还是要为其设置用户名和密码.本文主要介绍的是MongoDB权限管理之用户名和密码的操作,希望能对您有所帮助. 本 ...