Language:DefaultRiver Hopscotch
Time Limit: 2000MS |
|
Memory Limit: 65536K |
Total Submissions: 7990 |
|
Accepted: 3438 |
Description Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to R Ock in a river. The excitement takes place in a long, straight river with a rock at the start and another rock at the end, L unit S away from the start (1≤ L ≤1,000,000,000). Along the between the starting and ending rocks, N (0≤ n ≤50,000) more rocks appear Integral distance di from the start (0 < di < L). To play the game, each cow in turn starts at the starting rock and tries to reach the finish at the ending rock, jumping O Nly from rock to rock. Of course, less agile cows never make it to the final rock, ending up instead in the river. Farmer John is proud of he cows and watches this event each year. But as time goes by, he tires of watching the timid cows of the other farmers limp across the short distances between rock s placed too closely together. He plans to remove several rocks on order to increase the shortest distance a cow would have the to jump to reach the end. He knows he cannot remove the starting and ending rocks, but he calculates that he had enough resources to remove up to m Rocks (0≤ M ≤ N). FJ wants to know exactly how much he can increase the shortest distance *before* He starts removing the rocks. Help Farmer John determine the greatest possible shortest distance a cow have to jump after removing the optimal set of m Rocks. Input Line 1:three space-separated integers:L,N, andM Lines 2..N+1:each line contains a single integer indicating what far some rock was away from the starting rock. No Rocks share the same position.Output Line 1: A single integer which is the maximum of the shortest distance A cow have to jump after removingMRocksSample Input 25 5 2214112117
Sample Output 4
Hint Before removing any rocks, the shortest jump is a jump of 2 from 0 (the start) to 2. After removing the rocks at 2 and, the shortest required jump was a jump of 4 (from-to-or from-25).Source Usaco 2006 December Silver
|
Test instructions: Len length of the river, there are n blocks of stone, to remove the K block after the minimum length of Jump river to what is the maximum value?
I feel my mind is so limited, so bad
Idea: not easy to think of two points, the length of the jump to get the need to remove a few pieces of stone to see if the requirements are met
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath> #include <queue> #include <stack> #include <vector> #include <set> #include <map > #define L (x) (x<<1) #define R (x) (x<<1|1) #define MID (x, y) ((x+y) >>1) #define EPS 1e-8typedef __ Int64 ll; #define FRE (i,a,b) for (i = A; I <= b; i++) #define MEM (T, v) memset ((t), V, sizeof (t)) #define SF (n) scanf ("%d", &n) #define SFF (A, b) scanf ("%d%d", &a, &b) #define SFFF (a,b,c) scanf ("%d%d%d", &a, &b, &C) #define PF printf#define Bug pf ("hi\n") using namespace std; #define INF 0x3f3f3f3f#define N 50005i NT A[n],n,k,len;bool seach (int x) {int cur,i,step=0;cur=0;for (i=1;i<=n;i++) {if (a[i]-a[i-1]<x-cur) {step++;cur+ =A[I]-A[I-1];} elsecur=0;} if (step<=k) return true; The stone required to be removed is less than kelse return false;} int main () {int i,j;while (~SFFF (len,n,k)) {for (i=1;i<=n;i++) SF (A[i]), if (n<=k) {pf ("%d\n", Len); continue;} N++;a[n]=len;sort (a,a+n+1); int le=inf; for (i=1;i<n;i++) if (le>a[i]-a[i-1]) le=a[i]-a[i-1];int ri=len;int mid,ans;while (le<=ri) {Mid=MID (Le,ri); if (Seach (mid)) {Ans=mid; le=mid+1; The stone needed to be removed is less than k, indicating that the stone is removed, so ans may be larger}elseri=mid-1;} PF ("%d\n", ans);} return 0;}
POJ 3258 River Hopscotch (two minutes jump river)