题目:这里

题意:一条数轴上,有n个城市和m个塔,分别给出城市的位置和塔的位置,每个塔有个覆盖范围,问能将所有城市都覆盖的塔的最小范围是多少,一个城市只要被至少一个塔

覆盖就行。

可以利用贪心的思想模拟一下,注意一下细节就行,也可以二分。

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std; typedef long long ll;
const int M = 1e5 + ;
int a[M],b[M];
ll max(ll x,ll y){return x>y?x:y;} int main()
{
int n,m;
scanf("%d%d",&n,&m);
for (int i= ; i<=n ; i++) scanf("%d",&a[i]);
for (int i= ; i<=m ; i++) scanf("%d",&b[i]);
if (a[]>=b[m])
{
printf("%I64d\n",(ll)(a[n]-b[m]));
return ;
}
if (b[]>=a[n])
{
printf("%I64d\n",(ll)(b[]-a[]));
return ;
}
int j=;ll ans=;
for (int i= ; ; i++)
{
bool flag=false;
if (i>m) i=m;
while (i!=&&abs(a[j]-b[i])>=abs(a[j]-b[i-])&&j<=n)
j++,flag=true;
if (flag) ans=max(ans,abs(a[j-]-b[i-]));
if (j==n+) break;
ll dis=abs(b[i]-a[j]);
while (abs(b[i]-a[j])<=dis&&i<=m)
dis=abs(b[i]-a[j]),i++;
i--;
while (abs(a[j]-b[i])<=dis&&j<=n)
j++;
ans=max(ans,dis);
//cout<<ans<<endl;
if (j==n+) break;
}
printf("%I64d\n",ans);
return ;
}

二分

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std; typedef long long ll;
const int M = 1e5 + ;
ll a[M],b[M],n,m;
ll max(ll x,ll y){return x>y?x:y;} bool judge(ll x)
{
int j=;
for (int i= ; i<=m ; i++)
{
while (a[j]>=b[i]-x&&a[j]<=b[i]+x&&j<=n)
j++;
if (j==n+) return true;
}
return false;
} ll sreach ()
{
ll l=,r=3e9,ans=;
while (l<=r)
{
ll mid=(l+r)/;
if (judge(mid)) ans=mid,r=mid-;
else l=mid+;
}
return ans;
} int main()
{
scanf("%d%d",&n,&m);
for (int i= ; i<=n ; i++) scanf("%I64d",&a[i]);
for (int i= ; i<=m ; i++) scanf("%I64d",&b[i]);
if (a[]>=b[m])
{
printf("%I64d\n",(ll)(a[n]-b[m]));
return ;
}
if (b[]>=a[n])
{
printf("%I64d\n",(ll)(b[]-a[]));
return ;
} printf("%I64d\n",sreach());
return ;
}

Codeforces 702C Cellular Network的更多相关文章

  1. codeforces 702C Cellular Network 2016-10-15 18:19 104人阅读 评论(0) 收藏

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

  2. Codeforces 702C Cellular Network(二分)

    题目链接:http://codeforces.com/problemset/problem/702/C 题意: 在数轴上有N个城市和M个信号塔,给你这N个城市以及M个塔在数轴上的位置,求M个塔可以覆盖 ...

  3. codeforce 702C Cellular Network 二分答案

    http://codeforces.com/contest/702 题意:n个村庄,m个机站,问机站最短半径覆盖完所有村庄 思路:直接二分答案 二分太弱,调了半天..... // #pragma co ...

  4. codeforces 702C C. Cellular Network(水题)

    题目链接: C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input st ...

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

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

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

  7. Educational Codeforces Round 15 Cellular Network

    Cellular Network 题意: 给n个城市,m个加油站,要让m个加油站都覆盖n个城市,求最小的加油范围r是多少. 题解: 枚举每个城市,二分查找最近的加油站,每次更新答案即可,注意二分的时候 ...

  8. Educational Codeforces Round 15_C. Cellular Network

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

  9. CodeForce-702C Cellular Network(查找)

    Cellular Network CodeForces - 702C 给定 n (城市数量) 和 m (灯塔数量): 给定 a1~an 城市坐标: 给定 b1~bm 灯塔坐标: 求出灯塔照亮的最小半径 ...

随机推荐

  1. 全站 HTTPS 来了(转载)

    转载:本文为腾讯Bugly原创文章. 最近大家在使用百度.谷歌或淘宝的时候,是不是注意浏览器左上角已经全部出现了一把绿色锁,这把锁表明该网站已经使用了 HTTPS 进行保护.仔细观察,会发现这些网站已 ...

  2. Ninject之旅之十一:Ninject动态工厂(附程序下载)

    摘要 如果我们已经知道了一个类所有的依赖项,在我们只需要依赖项的一个实例的场景中,在类的构造函数中引入一系列的依赖项是容易的.但是有些情况,我们需要在一个类里创建依赖项的多个实例,这时候Ninject ...

  3. Yaf框架下类的自动加载

    前面两篇博客分别讲述了PHP自带的类加载和composer中类的自动加载,其实Yaf框架也实现了基于PSR0和PSR4的类的自动加载.根据我对Yaf下类的自动加载方式的理解写下这篇博客.由于接触Yaf ...

  4. Android 6.0权限适配

    targetSdkVersion 23以上,必须适配新的权限模式 安卓6.0及之后,权限分为三类  1.不涉及隐私的正常权限,如innernet2.危险权限 3.特殊权限 system_alert_w ...

  5. hive中rcfile格式(收藏文)

    首先声明,此文是属于纯粹收藏文,感觉讲的很不错. 本文介绍了Facebook公司数据分析系统中的RCFile存储结构,该结构集行存储和列存储的优点于一身,在MapReduce环境下的大规模数据分析中扮 ...

  6. Python 2.7_发送简书关注的专题作者最新一篇文章及连接到邮件_20161218

    最近看简书文章关注了几个专题作者,写的文章都不错,对爬虫和数据分析都写的挺好,因此想到能不能获取最新的文章推送到Ipad网易邮箱大师.邮件发送代码封装成一个函数,从廖雪峰大神那里学的  http:// ...

  7. Scala

    简直就是java啊,mac上,下载,添加环境变量,source 就好了

  8. 用VC进行COM编程所必须掌握的理论知识

    一.为什么要用COM 软件工程发展到今天,从一开始的结构化编程,到面向对象编程,再到现在的COM编程,目标只有一个,就是希望软件能象积方块一样是累起来的,是组装起来的,而不是一点点编出来的.结构化编程 ...

  9. 【转】HTML转义字符大全

    ISO Latin-1字符集:  — 制表符Horizontal tab  — 换行Line feed  — 回车Carriage Return  — Space ! ! — 惊叹号Exclamati ...

  10. springmvc spring mybatis插入mysql中文乱码

    springmvc 插入mysql数据库中文乱码问题: 1.将页面中的编码改成utf-8 2.用SQLyog右击->改变数据库 以上两步可以保证页面数据编码一致 3.在mybatis连接的地方加 ...