NOIP2015提高组 跳石头 ACM-ICPC2017香港 E(选择/移除+二分答案)
跳石头
题目背景
一年一度的“跳石头”比赛又要开始了!
题目描述
这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石。组委会已经选择好了两块岩石作为比赛起点和终点。在起点和终点之间,有 NN 块岩石(不含起点和终点的岩石)。在比赛过程中,选手们将从起点出发,每一步跳向相邻的岩石,直至到达终点。
为了提高比赛难度,组委会计划移走一些岩石,使得选手们在比赛过程中的最短跳跃距离尽可能长。由于预算限制,组委会至多从起点和终点之间移走 MM 块岩石(不能移走起点和终点的岩石)。
输入输出格式
输入格式:
第一行包含三个整数 L,N,ML,N,M,分别表示起点到终点的距离,起点和终点之间的岩石数,以及组委会至多移走的岩石数。保证 L \geq 1L≥1 且 N \geq M \geq 0N≥M≥0。
接下来 NN 行,每行一个整数,第 ii 行的整数 D_i( 0 < D_i < L)Di(0<Di<L), 表示第 ii 块岩石与起点的距离。这些岩石按与起点距离从小到大的顺序给出,且不会有两个岩石出现在同一个位置。
输出格式:
一个整数,即最短跳跃距离的最大值。
输入输出样例
说明
输入输出样例 1 说明:将与起点距离为 22和 1414 的两个岩石移走后,最短的跳跃距离为 44(从与起点距离 1717 的岩石跳到距离 2121 的岩石,或者从距离 2121 的岩石跳到终点)。
另:对于 20\%20%的数据,0 ≤ M ≤ N ≤ 100≤M≤N≤10。
对于50\%50%的数据,0 ≤ M ≤ N ≤ 1000≤M≤N≤100。
对于 100\%100%的数据,0 ≤ M ≤ N ≤ 50,000,1 ≤ L ≤ 1,000,000,0000≤M≤N≤50,000,1≤L≤1,000,000,000。
#include<bits/stdc++.h>
#define MAX 50005
using namespace std;
typedef long long ll; int a[MAX]; int main()
{
int t,i,j;
int L,N,M;
scanf("%d%d%d",&L,&N,&M);
a[]=;
for(i=;i<=N;i++){
scanf("%d",&a[i]);
}
a[N+]=L;
int l=,r=,m;
int ans=;
while(l<=r){
m=(l+r)/;
int pre=,cnt=;
for(i=;i<=N+;i++){
if(a[i]-a[pre]>=m){
pre=i;
cnt++;
} }
if(cnt>=N+-M){
ans=max(ans,m);
l=m+;
}
else{
r=m-;
}
}
printf("%d\n",ans);
return ;
}
跳石头(移除)
E
- 61.05%
- 2000ms
- 262144K
5G5G is the proposed next telecommunications standards beyond the current 4G4G standards. 5G5G planning aims at higher capacity than current 4G4G, allowing a higher density of mobile broadband users, and supporting device-to- device, reliable, and massive wireless communications. AA telecommunication company would like to install more base stations to provide better communication for customers. Due to the installation cost and available locations, the company can only install S (2 \le S \le L)S(2≤S≤L) base stations at L (2 \le L \le 100, 000)L(2≤L≤100,000) candidate locations. Since the base stations work in the same frequency band, they will interfere and cause severe performance degradation. To provide high quality communication experience to customers, the company would like to maximize the distance between the base stations so as to reduce the wireless interference among the base stations. Suppose the L candidate locations are in a straight line at locations P_1, P_2, ... , PL (0 \le Pi \le 1, 000, 000)P1,P2,...,PL(0≤Pi≤1,000,000) and the company wants to install SS base stations at the LL candidate locations. What is the largest minimum distance among the SS base stations?
Input
The input data includes multiple test sets.
Each set starts with a line which specifies LL (i.e.i.e., the number of candidate locations) and SS (i.e.i.e., the number of base stations). The next line contains LL space-separated integers which represent P_1P1 , P_2P2 , ... , P_LPL . The input data ends “00 00”.
Output
For each set, you need to output a single line which should be the largest minimum distance among the base stations.
For the first set, the 33 base stations can be installed at locations 2, 6, 112,6,11.
样例输入复制
5 3
2 3 9 6 11
4 3
1 4 9 10
0 0
样例输出复制
4
3
题目来源
#include<bits/stdc++.h>
#define MAX 100005
using namespace std;
typedef long long ll; int a[MAX]; int main()
{
int t,i,j;
int n,s;
while(scanf("%d%d",&n,&s)&&n+s){
for(i=;i<=n;i++){
scanf("%d",&a[i]);
}
sort(a+,a+n+);
int l=,r=,m;
int ans=;
while(l<=r){
m=(l+r)/;
int pre=,cnt=;
for(i=;i<=n;i++){
if(a[i]-a[pre]>=m){
pre=i;
cnt++;
} }
if(cnt>=s){
ans=max(ans,m);
l=m+;
}
else{
r=m-;
}
}
printf("%d\n",ans);
}
return ;
}
E(选择)
NOIP2015提高组 跳石头 ACM-ICPC2017香港 E(选择/移除+二分答案)的更多相关文章
- 洛谷 P2678 & [NOIP2015提高组] 跳石头
题目链接 https://www.luogu.org/problemnew/show/P2678 题目背景 一年一度的“跳石头”比赛又要开始了! 题目描述 这项比赛将在一条笔直的河道中进行,河道中分布 ...
- [NOIp2015提高组]跳石头
OJ题号:洛谷2678 思路:贪心+二分. 从前往后扫,一旦这个石头到上一个选的石头的距离小于二分的值就把这块石头移走. #include<cstdio> #include<queu ...
- P2678 [NOIP2015 提高组] 跳石头
#include<bits/stdc++.h> using namespace std; int l,n,m,a[100010];//与起点的距离 bool check(int d) { ...
- 【二分查找】 跳石头NOIP2015提高组 D2T1
[二分查找]跳石头NOIP2015提高组 D2T1 >>>>题目 [题目描述] 一年一度的“跳石头”比赛又要开始了! 这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石 ...
- 【题解】NOIP2015提高组 复赛
[题解]NOIP2015提高组 复赛 传送门: 神奇的幻方 \([P2615]\) 信息传递 \([P2661]\) 斗地主 \([P2668]\) 跳石头 \([P2678]\) 子串 \([P26 ...
- 【数据结构】运输计划 NOIP2015提高组D2T3
[数据结构]运输计划 NOIP2015提高组D2T3 >>>>题目 [题目描述] 公元 2044 年,人类进入了宇宙纪元.L 国有 n 个星球,还有 n−1 条双向航道,每条航 ...
- [NOIP2015 提高组] 运输计划题解
题目链接:P2680 [NOIP2015 提高组] 运输计划 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 看了好长时间题解才终于懂的,有关lca和二分答案的题解解释的不详细,一时 ...
- [NOIP2015] 提高组 洛谷P2615 神奇的幻方
题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1写在第一行的中间. ...
- 洛谷-神奇的幻方-NOIP2015提高组复赛
题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,--,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1写在第一行的中间. ...
随机推荐
- JavaScript中实现继承
今天即兴研究了下JS,查阅了相关资料 ,发现Js中没有"子类"和"父类"的概念,也没有"类"(class)和"实例"(i ...
- mysql的分库分表
1 什么是分库分表 这里讨论的情况是一台机器上对应一个数据库. 分库的对象是表,分表的对象是行.分库是说把属于同一个模块的相关性很高的表放在同一个数据库中.分表是说把同一个表的的行分成多个子表,把各个 ...
- Grunt学习笔记【6】---- grunt-contrib-requirejs插件详解
本文主要讲如何使用Grunt实现RequireJS文件压缩. 一 说明 ES6出来前,RequireJS是JavaScript模块化最常用的方式之一.对于使用RequireJS构建的项目,要实现打包压 ...
- YTST_CX_0001(ALV栏位汇总)
*********************************************************************** * Title : X ...
- 详解单页面路由的几种实现原理(附demo)
前言 路由是每个单页面网站必须要有的,所以,理解一下原理,我觉得还是比较重要的. 本篇,基本不会贴代码,只讲原理,代码在页底会有githup地址,主意,一定要放在服务本地服务器里跑(因为有ajax), ...
- 借助node.js + mysql 学习基础ajax~
很多小白不知道ajax怎么学,所以就弄了个node后台模拟下基本的ajax请求. 环境要求是安装node~ 先上linkMysql.js var mysql = require('mysql') va ...
- ceres求解BA第10章
1.前言g2o是根据边来保存每一个代价函数,它是在边类中构造误差函数,构造边的时候,会设置顶点.测量值.协方差矩阵等.而在ceres中,用problem类型来构造最终的目标函数.先是使用AddResi ...
- linux系统调用mount全过程分析【转】
本文转载自:https://blog.csdn.net/skyflying2012/article/details/9748133 系统调用本身是软中断,使用系统调用,内核也陷入内核态,异常处理,找到 ...
- java高级特性增强
第4天 java高级特性增强 今天内容安排: 1.掌握多线程 2.掌握并发包下的队列 3.了解JMS 4.掌握JVM技术 5.掌握反射和动态代理 java多线程增强 .1. java多线程基本知识 . ...
- BZOJ 1657 [Usaco2006 Mar]Mooo 奶牛的歌声:单调栈【高度序列】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1657 题意: Farmer John的N(1<=N<=50,000)头奶牛整齐 ...