Codeforces 702C Cellular Network
题目:这里
题意:一条数轴上,有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的更多相关文章
- 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 ...
- Codeforces 702C Cellular Network(二分)
题目链接:http://codeforces.com/problemset/problem/702/C 题意: 在数轴上有N个城市和M个信号塔,给你这N个城市以及M个塔在数轴上的位置,求M个塔可以覆盖 ...
- codeforce 702C Cellular Network 二分答案
http://codeforces.com/contest/702 题意:n个村庄,m个机站,问机站最短半径覆盖完所有村庄 思路:直接二分答案 二分太弱,调了半天..... // #pragma co ...
- codeforces 702C C. Cellular Network(水题)
题目链接: C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input st ...
- 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 Cellular Network
Cellular Network 题意: 给n个城市,m个加油站,要让m个加油站都覆盖n个城市,求最小的加油范围r是多少. 题解: 枚举每个城市,二分查找最近的加油站,每次更新答案即可,注意二分的时候 ...
- Educational Codeforces Round 15_C. Cellular Network
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- CodeForce-702C Cellular Network(查找)
Cellular Network CodeForces - 702C 给定 n (城市数量) 和 m (灯塔数量): 给定 a1~an 城市坐标: 给定 b1~bm 灯塔坐标: 求出灯塔照亮的最小半径 ...
随机推荐
- 简单的 Promise 实现
参考 http://www.tuicool.com/articles/RzQRV3 var PENDING = undefined, FULLFILLED = 1, REJECTED = 2; var ...
- OpenGL ES 中的模板测试
模板测试的主要功能是丢弃一部分片元,相对于深度检测来说,模板测试提出的片元数量相对较少.模板测试发生在剪裁测试之后,深度测试之前. 使用模板测试时很重要的代码提示: 1.glClear( GL_STE ...
- 为 Linux 应用程序编写 DLL[转]
自:http://www.ibm.com/developerworks/cn/linux/sdk/dll/index.html 在仅仅只会编写插件的时候为什么要编写整个应用程序? 插件和 DLL 通常 ...
- PE新手教程
先确定你的手机是 IPhone 还是 Android Android 的在你的应用商店搜索 我的世界 下载 0.14.2 版本 , 也可以在群文件中下载 安装 然后点击 下载 等待下载.. 下 ...
- Android-monkey稳定性测试(多台设备同时进行)
1.目的(原创文章,转载请注明出处-) 主要为指引开展android平台应用的稳定性测试,尽可能地在应用发布前发现crash及an ...
- lnmp编译安装
lnmp超详细编译安装教程 linux采用的是centos,软件包统一放在/usr/local/src目录下.由于 centos源比较老,而且更新起来也比较慢,此处建议你换成163源.提示:如果你真打 ...
- ToolStrip控件在窗体没有焦点的情况下,需要单击二次才能够激发事件的解决办法
protected override void WndProc(ref Message m) { if (m.Msg == 0x210) { Control control = Control.Fro ...
- 如何在Flex标签中写事件函数
在事件变量值中直接写函数语句,如果是多条语句,则用";"号隔开. 示例如下: <mx:Box id="label" backgroundColor=&qu ...
- BZOJ2037: [Sdoi2008]Sue的小球
Description Sue 和Sandy最近迷上了一个电脑游戏,这个游戏的故事发在美丽神秘并且充满刺激的大海上,Sue有一支轻便小巧的小船.然而,Sue的目标并不是当一个海 盗,而是要收集空中漂浮 ...
- 学习ExtJs教程初级
搭建环境:myeclipse10 +tomcat6+jdk6 新建一个webproject(启动myeclipse:file--new--webproject) 导入相关的js和css(百度下载就好. ...