Poj 3258 river hopscotch

Source: Internet
Author: User
River hopscotch Time limit:2000 ms Memory limit:65536kb 64bit Io format:% LLD & % llusubmit status

Description

Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a river. the excitement takes place on a long, straight river with a rock at the start and another rock at the end,LUnits away from the start (1 ≤L≤ 1,000,000,000). Along the river between the starting and enanswerng rocks,N(0 ≤N≤ 50,000) More rocks appear, each at an integral answerstanceAnswerFrom the start (0 <Answer<L).

To play the game, each cow in turn starts at the starting rock and tries to reach the finish at the enanswerng rock, jumping only from rock to rock. of course, less agile cows never make it to the final rock, enanswerng up instead in the river.

Farmer John is proud of his cows and watches this event each year. but as time goes by, he tires of watching the timid cows of the other farmers limp hosts ss the short answerstances between rocks placed too closely together. he plans to remove several rocks in order to increase the shortest answerstance a cow will have to jump to reach the end. he knows he cannot remove the starting and enanswerng rocks, but he calculates that he has enough resources to remove upMRocks (0 ≤MN).

FJ wants to know exactly how much he can increase the shortest answerstance* Before *He starts removing the rocks. Help Farmer John determine the greatest possible shortest answerstance a cow has to jump after removing the optimal setMRocks.

Input

Line 1: three space-separated integers: L, N, And M
Lines 2 .. N+ 1: each line contains a single integer inanswercating how far some rock is away from the starting rock. No two rocks share the same position.

Output

Line 1: A single integer that is the maximum of the shortest answerstance a cow has to jump after removing MRocks

Sample Input

25 5 2214112117

Sample output

4

Hint

Before removing any rocks, the shortest jump was a jump of 2 from 0 (the START) to 2. after removing the rocks at 2 and 14, the shortest required jump is a jump of 4 (from 17 to 21 or from 21 to 25 ).

Question:
The length of a river is L. the start and end of the river have two stones respectively, and the distance from S to E is L. There are n stones in the river, and each stone has a unique distance to S. Q: I want to remove M stones now (except s and e). I want to remove M stones, make the shortest distance at that time as big as possible and output the shortest distance.
---------------------
Calm smile
Source: csdn
Original: 51025699
Copyright Disclaimer: This article is an original article by the blogger. For more information, see the blog post link!

Solution:
Answer must be in the range [0, l ],
Then we can look for answer in two ways, so that the answer selects stones in sequence, and the number is marked as num,
If num <= m, it indicates that answer is selected to be smaller, so low = Mid + 1; answer = mid; (answer = mid, because the number of num with less than mid is smaller than m,
That is to say, if answer is the final answer at this time, the number of stones to be moved is smaller than m, and the remaining number of moves can be moved, without affecting the result at this time, so the answer = mid

If num> m, the answer value is greater. In this case, high = mid-1;
# Include <stdio. h ># include <algorithm> using namespace STD; int N; int main () {int L, M, I, ans; int Dist [50000 + 5]; while (~ Scanf ("% d", & L, & N, & M) {Dist [0] = 0; Dist [n + 1] = L; for (I = 1; I <= N; I ++) scanf ("% d", DIST + I); sort (Dist + 1, DIST + n + 1 ); int low = 0, high = L; while (high-low> = 0) {int num = 0, present = 0, mid = (low + high)> 1, sum = 0; for (I = 1; I <= n + 1; I ++) if (sum + = DIST [I]-Dist [I-1]) <mid) // if the distance between adjacent stones is smaller than the predefined maximum and minimum mid distance, the stone num ++ is removed once. Else sum = 0; If (Num <= m) // The number of moves is less than m, that is, the stone with spacing less than mid is less than m, indicating that the mid should be larger {LOW = Mid + 1; ans = mid ;} else high = mid-1;} printf ("% d \ n", ANS);} return 0 ;}

 

 

 

Poj 3258 river hopscotch

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.