题目:这里

题意:一条数轴上,有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. bashrc

    # ~/.bashrc: executed by bash(1) for non-login shells.# see /usr/share/doc/bash/examples/startup-fil ...

  2. Android7.0 新特性

    删除了三个隐式广播 1.监听网络变化的广播 CONNECTIVITY_ACTION,在Manifest.xml中注册的 不会受到,在前台运行的程序 registerReceiver()注册的广播可以接 ...

  3. 随便翻翻qcon 2014

    随便翻了翻QCon 2014的ppt,土人看看最新的成果: 基本感受: 1. 高大上公司比如阿里,腾讯啥的已经挺过第一轮,已经重构重构再重构了,整个架构不能说成熟,但是可以说可用了 2. 创业公司或者 ...

  4. Java开发环境配置

    JDK下载地址: http://www.oracle.com/technetwork/java/javase/downloads/index.html 安装:双击exe文件一直下一步就Ok了. 环境变 ...

  5. R 统计学工具部署和使用

    由于公司内部对于市场数据分析的需求,要求引入R统计工具,并集成到报表工具中.对于R的介绍,大家请百度一下,当然,最好能去看官方的说明 https://www.r-project.org/ 下面简单介绍 ...

  6. final的使用

    final对基本类型,限定常量. final对对象的引用,不可引用其他对象. final的字段,必须在定义时或者构造器内完成初始化.构造内才完成初始化的Blank Final(空白final). cl ...

  7. jquery 使用方法(二)

    jquery語法: jquery語法是為html元素的选取编制的,可以对元素执行某些操作. 基础语法是:$(selector).action() 美元符号定义 jQuery 选择符(selector) ...

  8. MVC过滤器详解

    MVC过滤器详解   APS.NET MVC中(以下简称"MVC")的每一个请求,都会分配给相应的控制器和对应的行为方法去处理,而在这些处理的前前后后如果想再加一些额外的逻辑处理. ...

  9. win8 VB6打开提示MSCOMCTL.ocx未注册

    从xp上复制相应的文件到win8相应的位置,如果是不可以,win8中反注册此控件,再注册此控件

  10. tomcat开机启动

    最近老板租了个阿里云的服务器,动不动就自动重启,搞得我还得有事没事盯着服务器,谁知道它什么时候会重启啊,为了让自己不要那么累,也为了不要造成不必要的麻烦,还是把tomcat改成开机启动的程序吧. 网上 ...