题目:这里

题意:一条数轴上,有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. jquery easyui校验select下拉列表值是否为空的问题

    属性名 类型 描述 默认值 required 布尔 定义文本域是否为必填项 false validType 字符串 定义字段的验证类型,比如email, url, etc. null missingM ...

  2. CHARINDEX

    实现查询条件多个值的或的关系 Select Id,Name from CustTable where CharIndex( CustTable.Name, 'ACDE,BEX,CCC')>0 C ...

  3. MFC 编辑框中字体大小改变,行高不能改变,只能显示一半的问题,已解决。

    CKagulaCEdit是CEdit的一个继承类,m_edit的CKagulaCEdit类型的一个变量 调用的时候,是这样的: 编辑框中字体大小改变,行高不能改变,只能显示一半的问题,问题如下: 这时 ...

  4. MySQL之权限管理

    MySQL之权限管理 一.MySQL权限简介 关于mysql的权限简单的理解就是mysql允许你做你全力以内的事情,不可以越界.比如只允许你执行select操作, 那么你就不能执行update操作.只 ...

  5. js部分总结

    1 currentStyle 可以获取行间样式,但是不兼容 其他浏览器用getComputedStyle(div,null)这个ie低级版本不兼容; if(div.currentStyle){ } e ...

  6. 获取iPhone 联系人列表,并且根据分析得到的姓名首字母进行排序

    获取手机联系人以iOS9为分界点,大家都知道到了iOS9很多方法都更新了,好多接口都弃用,被新的接口代替.这Demo种有新旧两个接口,使用前判断当前iOS版本. 下面是Demo连接地址:Github的 ...

  7. VUE 入门基础(4)

    四,计算属性 基础例子 <div id='example'> <p>0riginal message: "{{message}}"</p> &l ...

  8. 分支界定法 branch-and-bound 分析与实现)(转载)

    1. 介绍分支界定法之前需要了解一下广度优先搜索breadth-First-search(BFS) 1.从图中某个顶点V0出发,并访问此顶点:以层为顺序,一层一层往下遍历 2.从V0出发,访问V0的各 ...

  9. RPC 框架通信原理

    RPC是指远程过程调用,也就是说两台服务器A,B,一个应用部署在A服务器上,想要调用B服务器上应用提供的函数/方法,由于不在一个内存空间,不能直接调用,需要通过网络来表达调用的语义和传达调用的数据: ...

  10. Altium Designer15 卡在登陆界面解决办法:

    Altium Designer15 卡在登陆界面解决办法: 在我的电脑系统盘中找到下面目录(注:如果看不到,需要取消隐藏文件选项.) C:\Documents and Settings\Adminis ...