P2678 Jumping Stones
-
- Topic provider 2014 Baiyong
- Label Two-point greedy
- Difficulty popularization/improvement-
Submit a discussion of the problem record
Recent discussions
- Error number 216??
- Greedy ah ah ah ah ah
Topic background The annual "Rock-jumping" competition begins again! Title description
The race will be carried out in a straight channel, with some huge rocks in the river. The organizing committee has chosen
Two rocks were chosen as the starting and ending points of the game. Between the starting and ending points, there are N blocks of rock (rocks without start and end points). In the course of the game, the contestants will start from the starting point and each step jumps to the adjacent rocks until they reach the end point.
In order to improve the difficulty of the game, the organizing committee plans to remove some rocks, so that players in the course of the shortest jump distance as long as possible. Due to budgetary constraints, the organizing committee removes the M-block rock from between the starting point and the end point (the rock cannot be removed from the starting and ending points).
Input output Format input format:
The input file name is stone.in.
The first line of the input file contains three integer l,n,m, representing the distance from the starting point to the end point, the number of rocks between the start and end points, and the number of rocks removed by the organizing committee.
The next N rows, one integer per line, and the integer Di (0 < di < L) of line I, represent the distance between the block I rock and the starting point. These rocks are given in the order of starting from small to large, and no two rocks will appear in the same position.
Output format:
The output file name is Stone.out. The output file contains only one integer, which is the maximum value for the shortest hop distance.
Input and Output Sample input example # #:
25 5 2) 2111417 21
Sample # # of output:
4
Description
Input/Output Sample 1 Description: After removing two rocks with a starting distance of 2 and 14, the shortest jump distance is 4 (from the rock with the starting distance of 17 to the rock at the distance of 21, or from the rock of the distance 21 to the end).
Another: For 20% of data, 0≤m≤n≤10. For 50% of data, 0≤m≤n≤100.
For 100% of data, 0≤m≤n≤50,000,1≤l≤1,000,000,000.
Analysis: Last year to do this problem yy a super strange greedy, And then took 30 points. In fact, for this problem, see the minimum value, but also can easily prove monotonic, so with two points. Then we have two points this minimum value, if there are two stones between the distance than this value is still small, so long remove this stone, see the last move of the number of stones more than M can.
#include <cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespacestd;inta[50010], N, M, L,ans;BOOLCheckintx) { intLast =0, cnt =0; for(inti =1; I <= N; i++) { if(A[i]-last <x) CNT++; Else Last=A[i]; } if(CNT >m)return false; return true;}intMain () {scanf ("%d%d%d", &l, &n, &m); for(inti =1; I <= N; i++) scanf ("%d", &A[i]); a[++n] =L; intL =0, r =L; while(L <=r) {intMid = (L + r)/2; if(check (mid)) {ans=mid; L= Mid +1; } ElseR= Mid-1; } printf ("%d\n", ans); return 0;}
Noip2015 Jumping Stones