POJ 3258 River Hopscotch

Source: Internet
Author: User

River Hopscotch
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 11031 Accepted: 4737

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 distancedi 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≤ MN).

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, and M
Lines 2.. N+1:each line contains a single integer indicating how 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 removing M Rock S

Sample 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).

Source

Usaco 2006 December Silver

The data range is very large, the scan will be T, so consider divide and conquer.

Take a stone, the front of the stone and the side of the back will be merged, due to consider the length of the new side, so the original order between the stones must be preserved, then the separation of the length of the side to lock the answer.

So have to determine the answer directly between the 0 and the maximum length of the two points.

Each time you scan an edge by the answer you try, delete all edges that are less than the answer and record the number of stones taken. After sweep, if the number of stones removed more than the limit, the answer is not feasible, continue to two points, if the number of stones removed less than the limit, there is a better solution, continue to two points.

1#include <algorithm>2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cmath>6 using namespacestd;7 Const intmxn=100500;8 Long Longle,n,m;9 Long LongDIS[MXN];Ten intmid; One Long Longans=0; A intcl () { -     intCnt=0; -     intlasum=0; the      for(intI=1; i<=n;i++){ -lasum+=dis[i]-dis[i-1]; -         if(lasum<mid) { -cnt++; +}Elselasum=0;//Qing 0 -     } +     if(cnt>m)return 0;//more stones to remove than the number of stones to remove A     return 1;  at } - intMain () { -scanf"%lld%lld%lld",&le,&n,&m); -     inti,j; -      for(i=1; i<=n;i++) scanf ("%lld",&dis[i]); -dis[n+1]=Le; inSort (dis+1, dis+n+2); -n+=1; to     intL=0, r=Le; +      while(l<=R) { -Mid= (l+r) >>1; the         if(CL ())//feasible *{l=mid+1; ans=mid;} $         Elser=mid-1;Panax Notoginseng     } -printf"%lld\n", ans); the     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.