Cellular Network

题意:

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

题解:

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

代码:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int INF=0x3f3f3f3f;
  5. const ll LINF=0x3f3f3f3f3f3f3f3f;
  6. #define PU puts("");
  7. #define PI(A) cout<<A<<endl
  8. #define SI(N) cin>>N
  9. #define SII(N,M) cin>>N>>M
  10. #define cle(a,val) memset(a,(val),sizeof(a))
  11. #define rep(i,b) for(int i=0;i<(b);i++)
  12. #define Rep(i,a,b) for(int i=(a);i<=(b);i++)
  13. #define reRep(i,a,b) for(int i=(a);i>=(b);i--)
  14. #define dbg(x) cout <<#x<<" = "<<x<<endl
  15. #define PIar(a,n) rep(i,n)cout<<a[i]<<" ";cout<<endl;
  16. #define PIarr(a,n,m) rep(aa,n){rep(bb, m)cout<<a[aa][bb]<<" ";cout<<endl;}
  17. const double EPS= 1e-9 ;
  18. /* ///////////////////////// C o d i n g S p a c e ///////////////////////// */
  19. const int MAXN= 100000 + 9 ;
  20. ll city[MAXN],oil[MAXN];
  21. ll N,M;
  22. int main()
  23. {
  24. iostream::sync_with_stdio(false);
  25. cin.tie(0);
  26. cout.tie(0);
  27. while(SII(N,M))
  28. {
  29. rep(i,N)SI(city[i]);
  30. rep(i,M)SI(oil[i]);
  31. ll ans=0;
  32. rep(i,N)
  33. {
  34. ll t=lower_bound(oil,oil+M,city[i])-oil;
  35. ll d=LINF;
  36. if (t<M)
  37. d=abs(oil[t]-city[i]);
  38. ll d2=LINF;
  39. if (t-1>=0)
  40. d2=abs(oil[t-1]-city[i]);
  41. ans=max(ans,min(d,d2));
  42. }
  43. PI(ans);
  44. }
  45. return 0;
  46. }

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. URAL 1930 Ivan's Car(BFS)

    Ivan's Car Time limit: 1.5 secondMemory limit: 64 MB The world is in danger! Awful earthquakes are d ...

  2. UVALive-4670 Dominating Patterns(AC自动机)

    题目大意:找出出现次数最多的模式串. 题目分析:AC自动机裸题. 代码如下: # include<iostream> # include<cstdio> # include&l ...

  3. [原创]cocos2d-x研习录-第一阶 背景介绍 之 cocos2d家族史

    Cocos2D是一个2D开源游戏引擎,它最早是由Ricardo Quesada(阿根廷人,社区简称Riq)和他的朋友们用Python开发的,用于开发2D游戏和基于2D图形的任何应用.最早引擎的名字源自 ...

  4. fs event_socket

    mod_event_socket     Skip to end of metadata   Created by John Boteler, last modified by Niek Vlesse ...

  5. cluster,network

    How cluster works https://technet.microsoft.com/en-us/library/cc738051(v=ws.10).aspx http://blogs.te ...

  6. JSBinding + SharpKit / 需要注意及不支持的列表

    1) 序列化不支持 public List<T>,其余都支持(JSBinding+Bridge无此功能) 2015年11月5日 补充:序列化只处理 Field.目前发现 Animation ...

  7. DATA GUARD架构(一)

    Data Guard传输-应用架构.>图1-1 ------------------------------------------------------------ 重做传输架构>图1 ...

  8. Quarzt.NET 任务调度框架

      Quartz.NET是一个开源的作业调度框架,是 OpenSymphony 的 Quartz API 的.NET移植,它用C#写成,可用于winform和asp.net应用中.它提供了巨大的灵活性 ...

  9. 虚拟化之vmware-vsphere概念,原理,功能

    080-login-back.vmx .encoding = "UTF-8"config.version = "8"virtualHW.version = &q ...

  10. linux服务之svn

    架构:c/s 开发语言:python 服务器端:在linux平台下部署 客户端:分gui与cli两种操作界面 相关包: http://blog.sina.com.cn/s/blog_53b95aec0 ...