当前位置:网站首页>(POJ - 3258) River hopper (two points)
(POJ - 3258) River hopper (two points)
2022-07-06 16:09:00 【AC__ dream】
Topic link :River Hopscotch - POJ 3258 - Virtual Judge
The question :
Every year cows hold various special versions of house jumping competitions , Including jumping from one rock to another in the river . This exciting activity is carried out in a long straight river , At start point and distance start point L There is a rock at the far end (1 ≤ L ≤ 10^9). Between the beginning and the end , Yes N A rock (0 ≤ N ≤ 50000), The distance between each rock and the starting point is Di (0 < Di < L).
In the course of the game , Cows take turns starting from the starting point , Try to reach the end , Each step can only jump from one rock to another . Of course , Weak cows cannot reach the finish line , He quit the race in the middle of the river .
Farmer John is proud of his cows and watches the race every year . But over time , Watching the timid cows of other farmers move slowly between the rocks close to each other , He felt very bored . He plans to remove some rocks , Make the process from the beginning to the end , The shortest jump distance is the longest , The distance from jumping to the end is not counted . He can remove at most... Except the beginning and the end M A rock (0 ≤ M ≤ N).
Please help farmer John make sure : After removing these rocks , What is the maximum value of the shortest jump distance ?
Input
The first 1 The line contains three integers separated by a single space L, N, M.
The first 2 To N + 1 That's ok , One integer per row , Represents the distance between each rock and the starting point . There won't be two rocks in the same place .
Output
Output an integer , That is, the maximum value of the shortest jump distance .
Sample input
25 5 2 2 14 11 21 17
Sample output
4
analysis : A simple analysis shows that the answer is monotonic , Now suppose that the number of stones we can remove is uncertain , That is to say, if the shortest jumping distance is x The number of stones to be removed is y, Then for any shortest jumping distance is u(u>x) The minimum number of stones to be removed in the scheme v Must be greater than or equal to y, So we can calculate the shortest distance according to this dichotomy , Each time, judge whether the shortest distance is larger or smaller by comparing the number of stones that need to be removed with the given number of stones that can be removed , The specific comparison method is as follows :
The shortest jumping distance is x The number of stones to be removed is y, if y<=m, In other words, we can increase the shortest distance by removing a few more stones , So is x Less than or equal to the correct answer , The opposite is greater than the correct answer
Attention to detail : When the shortest jumping distance is x The number of stones to be removed is y, if y=m, be x Not necessarily the answer , In fact, at this time x Is less than or equal to the correct answer
Here is the code :
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
using namespace std;
const int N=5e4+10;
int a[N],n,m,L;
bool check(int x)
{
int cnt=0,r=0;// Record the minimum number of stones that need to be removed ,r For the position of the last stone
for(int i=1;i<=n+1;i++)
{
if(a[i]-r<x) cnt++;// Once the distance is less than x Then the stone will be removed
else r=a[i];
}
if(cnt<=m) return true;// The answer is too small
return false;
}
int main()
{
cin>>L>>n>>m;
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
a[n+1]=L;
sort(a+1,a+n+1);
int l=1e9+10,r=1e9+10,mid;
for(int i=1;i<=n+1;i++)
l=min(l,a[i]-a[i-1]);
while(l<r)
{
mid=l+r+1>>1;
if(check(mid)) l=mid;
else r=mid-1;
}
printf("%d",l);
return 0;
}
边栏推荐
- Nodejs+vue online fresh flower shop sales information system express+mysql
- 树莓派4B安装opencv3.4.0
- 树莓派CSI/USB摄像头使用mjpg实现网页摄像头监控
- 2078. Two houses with different colors and the farthest distance
- Penetration test (2) -- penetration test system, target, GoogleHacking, Kali tool
- Luogu P1102 A-B number pair (dichotomy, map, double pointer)
- [exercise-3] (UVA 442) matrix chain multiplication
- Radar equipment (greedy)
- 969. Pancake sorting
- “鬼鬼祟祟的”新小行星将在本周安全掠过地球:如何观看
猜你喜欢
Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures
Differential (one-dimensional, two-dimensional, three-dimensional) Blue Bridge Cup three body attack
2078. Two houses with different colors and the farthest distance
605. Planting flowers
Ball Dropping
b站 实时弹幕和历史弹幕 Protobuf 格式解析
C language is the watershed between low-level and high-level
1529. Minimum number of suffix flips
969. Pancake sorting
Gartner: five suggestions on best practices for zero trust network access
随机推荐
b站 实时弹幕和历史弹幕 Protobuf 格式解析
基于web的照片数码冲印网站
[exercise 4-1] cake distribution
Gartner: five suggestions on best practices for zero trust network access
D - function (HDU - 6546) girls' competition
Find 3-friendly Integers
Research Report on surgical fluid treatment industry - market status analysis and development prospect prediction
【练习4-1】Cake Distribution(分配蛋糕)
Information security - Epic vulnerability log4j vulnerability mechanism and preventive measures
信息安全-安全编排自动化与响应 (SOAR) 技术解析
[exercise-5] (UVA 839) not so mobile (balance)
JS call camera
Nodejs+vue online fresh flower shop sales information system express+mysql
1903. Maximum odd number in string
628. Maximum product of three numbers
China potato slicer market trend report, technical dynamic innovation and market forecast
C language must memorize code Encyclopedia
Quick to typescript Guide
Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
Research Report of exterior wall insulation system (ewis) industry - market status analysis and development prospect prediction