当前位置:网站首页>Luogu p2678 stone jumping
Luogu p2678 stone jumping
2022-06-10 03:03:00 【Volume C】
https://www.luogu.com.cn/problem/P2678
[NOIP2015 Improvement group ] Rock jumping
Background
annual “ Rock jumping ” The game is about to start again !
Title Description
The competition will be held in a straight river , There are some huge rocks in the river . The organizing committee has selected two rocks as the starting and ending points of the competition . Between the beginning and the end , Yes N N N A rock ( Rock without start and end ). In the course of the game , The players will start from the starting point , Each step jumps to the adjacent rock , Until we reach the end .
In order to improve the difficulty of the competition , The organizing committee plans to remove some rocks , Make the shortest jumping distance of players in the competition as long as possible . Due to budget constraints , At most, the organizing committee will move from the starting point to the end point M M M A rock ( You can't remove the rocks at the beginning and the end ).
Input format
The first line contains three integers L , N , M L,N,M L,N,M, The distance from the starting point to the ending point , The number of rocks between the beginning and the end , And the maximum number of rocks removed by the Organizing Committee . Guarantee L ≥ 1 L \geq 1 L≥1 And N ≥ M ≥ 0 N \geq M \geq 0 N≥M≥0.
Next N N N That's ok , One integer per row , The first i i i The whole number of lines D i ( 0 < D i < L ) D_i( 0 < D_i < L) Di(0<Di<L), It means the first one i i i The distance between the rock and the starting point . These rocks are given in the order of small to large distance from the starting point , And there won't be two rocks in the same place .
Output format
An integer , That is, the maximum value of the shortest jump distance .
Examples #1
The sample input #1
25 5 2
2
11
14
17
21
Sample output #1
4
Tips
I/o sample 1 explain : The distance from the starting point will be 2 2 2 and 14 14 14 After the removal of the two rocks , The shortest jump distance is 4 4 4( Distance from the starting point 17 17 17 The rock jumps to the distance 21 21 21 The rock of , Or from distance 21 21 21 The rock jumped to the end ).
another : about 20 % 20\% 20% The data of , 0 ≤ M ≤ N ≤ 10 0 ≤ M ≤ N ≤ 10 0≤M≤N≤10.
about 50 % 50\% 50% The data of , 0 ≤ M ≤ N ≤ 100 0 ≤ M ≤ N ≤ 100 0≤M≤N≤100.
about 100 % 100\% 100% The data of , 0 ≤ M ≤ N ≤ 50 , 000 , 1 ≤ L ≤ 1 , 000 , 000 , 000 0 ≤ M ≤ N ≤ 50,000,1 ≤ L ≤ 1,000,000,000 0≤M≤N≤50,000,1≤L≤1,000,000,000.
Here's a row for you N A stone , You can move M A stone , Make the distance between the smallest two stones as long as possible ,N,M≤50000.
Ideas
Binary search right boundary
Code 1
#include<iostream>
using namespace std;
const int N=50010;
int L,n,m;
int d[N];
bool check(int mid) {
int cnt=0,last=0;//
for(int i=1;i<=n;i++) {
if(d[i] - last < mid) cnt++;// Take the stone
else last=d[i]; // Skip if you don't take it
}
return cnt<=m;
}
int main()
{
scanf("%d%d%d",&L,&n,&m);
for(int i=1;i<=n;i++) {
scanf("%d",&d[i]);
}
n++;
d[n] = L;// Store the end distance
int l = 1 ,r = 1000000000; //r Take the maximum value to ac
while (l < r) {
// Binary search right boundary Because it's looking for Maximum
int mid = (l + r + 1) /2;//check() The() function determines that the answer is in mid Left or right
if (check(mid))
l = mid;
else r = mid - 1;
}
printf("%d\n",r);// When r==l Jump out of the loop , Now find the answer , Output r or l Fine
return 0;
}
Thank you for reading
边栏推荐
- 1px問題
- Summary and implementation of NLP keyword extraction methods
- 公众号留存操作时应该注意哪些问题?
- Robustness problem -- a work of Enlightenment
- bad interpreter:No such file or directory
- 使用gdi实现多路视频流合并
- DataFrame日期数据处理
- 鲁棒性问题——醍醐灌顶之作
- Flutter dual end scanning download app
- P1082 [noip2012 improvement group] congruence equation
猜你喜欢

新增收货地址【项目 商城】

Postgresql中如何终止正在执行的查询

微电网数字孪生 | 智能时代,部署源网荷储一体化管控平台

Anaconda modify file save path

promise 介绍和实现

Esp32 intrinsic function / variable cannot jump to definition

qiankun 如何提取出公共的依赖库

多线程并发

OpenCL memory optimization

Analysis of the meaning of autocorrelation function / autocovariance function in different fields
随机推荐
Development of direct interface
P1516 青蛙的约会(扩欧)
Numpy矩阵操作
鲁棒性问题——醍醐灌顶之作
Xmake v2.6.6 release, distributed compilation and cache support
Flutter dual end scanning download app
Dataframe date data processing
Knight Moves
npm 报错 Class extends value undefined is not a constructor or null
leetcode:305. 岛屿的数量
获取省市区的名称【项目 商城】
Timestamp transform to standard time format
Sql Server sql语句创建索引
FPGA can perform binocular and monocular operations
Tensorflow. Mobilenet for getting started with JS
修改pycharm缓存文件路径
17 orthogonal matrix and gram Schmidt orthogonalization
Lua的模块和包
在子集合中第一个元素是由另一个数组插入的
18行列式及其性质