Codeforces702C【二分】
题意:
给你几个城市,蜂窝塔量;
给出城市和塔的坐标可以重叠,非递减的方式给出;
输出最小的r,以至于所有的城市能被覆盖到;
思路:
目的就是要使每个城市覆盖到,那我对每个城市找离最近塔的距离,然后在这些距离里面找一个最大的就好了。
怎么对每个城市找离其最近的塔呢?
可以直接lower_bound,找到位置,然后距离比小就好了,但是每次答案要取大;
#include<cstdio>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N=1e5+10;
LL a[N];
LL b[N];
int n,m;
int main()
{
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
scanf("%I64d",&a[i]);
for(int i=0;i<m;i++)
scanf("%I64d",&b[i]);
LL ans=0;
for(int i=0;i<n;i++)
{
int x=lower_bound(b,b+m,a[i])-b;
LL temp;
if(x==0)
temp=abs(a[i]-b[x]);
else if(x==m)
temp=abs(a[i]-b[m-1]);
else
temp=min(abs(a[i]-b[x]),abs(a[i]-b[x-1]));
ans=max(ans,temp);
}
printf("%I64d\n",ans);
return 0;
}
Codeforces702C【二分】的更多相关文章
- BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 8748 Solved: 3835[Submi ...
- BZOJ 2756: [SCOI2012]奇怪的游戏 [最大流 二分]
2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 3352 Solved: 919[Submit][Stat ...
- 整体二分QAQ
POJ 2104 K-th Number 时空隧道 题意: 给出一个序列,每次查询区间第k小 分析: 整体二分入门题? 代码: #include<algorithm> #include&l ...
- [bzoj2653][middle] (二分 + 主席树)
Description 一个长度为n的序列a,设其排过序之后为b,其中位数定义为b[n/2],其中a,b从0开始标号,除法取下整. 给你一个长度为n的序列s. 回答Q个这样的询问:s的左端点在[a,b ...
- [LeetCode] Closest Binary Search Tree Value II 最近的二分搜索树的值之二
Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...
- [LeetCode] Closest Binary Search Tree Value 最近的二分搜索树的值
Given a non-empty binary search tree and a target value, find the value in the BST that is closest t ...
- jvascript 顺序查找和二分查找法
第一种:顺序查找法 中心思想:和数组中的值逐个比对! /* * 参数说明: * array:传入数组 * findVal:传入需要查找的数 */ function Orderseach(array,f ...
- BZOJ 1305: [CQOI2009]dance跳舞 二分+最大流
1305: [CQOI2009]dance跳舞 Description 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲 ...
- BZOJ 3110 [Zjoi2013]K大数查询 ——整体二分
[题目分析] 整体二分显而易见. 自己YY了一下用树状数组区间修改,区间查询的操作. 又因为一个字母调了一下午. 貌似树状数组并不需要清空,可以用一个指针来维护,可以少一个log 懒得写了. [代码] ...
随机推荐
- 最近遇到的C++数字和字符串的转换问题
1. 用itoa 和atoi 在头文件#include<cstidlib> itoa用法: char * itoa ( int value, char * str, int base ) ...
- go test test & benchmark
开发程序其中很重要的一点是测试,我们如何保证代码的质量,如何保证每个函数是可运行,运行结果是正确的,又如何保证写出来的代码性能是好的,我们知道单元测试的重点在于发现程序设计或实现的逻辑错误,使问题及早 ...
- Accelerated processing unit
http://en.wikipedia.org/wiki/Accelerated_processing_unit Accelerated processing unit From Wikipedia, ...
- Python演绎的精彩故事(二)
书接上回.在展示了App最顶层的代码后,我们去看看各模块怎样编程. 为了能看懂各模块的代码,首先须要铺垫一下Softchip架构的基本概念和设计规范. 1.随意模块不持有其它模块的实例.自然不再显式使 ...
- [Python-MATLAB] 在Python中调用MATLAB的API
可以参考官方的说明文档: http://cn.mathworks.com/help/matlab/matlab_external/get-started-with-matlab-engine-for- ...
- openwrt network 初始化
openwrt 烧写完成之后, 第一次启动会设置 network 的相关参数, 如 ip地址, mac地址, 等. 这里跟踪一下启动之后直到网络参数设置的过程. /sbin/init -> pr ...
- Spark 学习笔记:(四)MLlib基础
MLlib:Machine Learning Library.主要内容包括: 数据类型 统计工具 summary statistics correlations stratified sampling ...
- python day - 8 文件
文件的相关操作 1.文件的两种路径 绝对路径:需要从根目录下一层一层往下去找,文件或者程序所在的地方,中间所经过的所有的路径到你要找的文件或程序,就是绝对路径. 相对路径:只需要将要找的文件或者程序, ...
- 时光轴一之listView实现时光轴效果
尼玛.非要搞什么时光轴,一想简单的不就是个listView吗,然后一步一步来就好了,哈哈别看那么好看事实上不要想多了. 时光轴timeline最大的作用就是把过去的事物系统化.完整化.精确化.时间轴可 ...
- swift的String处理
import UIKit import CoreText class ViewController: UIViewController { override func viewDidLoad() { ...