poj3258--Two-point optimization

Source: Internet
Author: User

poj3258--Two-point optimization of river Hopscotch
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 8201 Accepted: 3531

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≤ 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 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 removing MRocks

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-25). Test instructions: Some stones are lined up in a line, the first and last can not be removed, the rest of the total may be removed m block, to remove the minimum value of the stone spacing maximum thinking: and poj3273 almost exactly the same, the same two points, the same use of two i,j pointers for greedy judgment, But two ticks to note is poj3273 in mid= (Low+high)/2, and here mid= (Low+high)/2+1, because here is the largest, (2+3)/2=2, instead of equal to 3 or 2.5, if there is no + 1, will die loop.
/** start at 16:40 * end at 17:21 * time:41 min * problem:poj3258 **/#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespaceStd;typedefLong Longll;Const intmaxn=1000100;Constll inf= (1ll<< -); ll L;intN,m;ll POS[MAXN];//int Times=1;BOOLjudge (ll limit) {//cout<<times++<<endl;    intDel_cnt=0;  for(intI=0, j=1; j<=n+1; j + +) {///control greed with the I and J Pointers        if(Pos[j]-pos[i]<limit) del_cnt++; ElseI=J; }    if(del_cnt<=m)return true; return false;} ll Binsearch (ll Low,ll high) { while(low<High ) {ll Mid= (Low+high)/2+1;///here is Low=mid, so here +1, if the following is High=mid, then not +1. Because (2+3)/2=2, instead of equal to 3 or 2.5, the processing here avoids a dead loop        //cout<<low<< "" <        if(Judge (mid)) low=mid; Elsehigh=mid-1; }    returnLow ;}intMain () { while(SCANF ("%lld%d%d", &l,&n,&m)! =EOF) {pos[0]=0; Pos[n+1]=L;  for(intI=1; i<=n;i++) scanf ("%lld",&Pos[i]); Sort (Pos,pos+n+1); //for (int i=0;i<=n+1;i++) cout<<i<< "" <<pos[i]<<endl;ll min=INF;  for(intI=1; i<=n+1; i++){            if(pos[i]-pos[i-1]<min) min=pos[i]-pos[i-1]; }        //cout<<min<<endl;printf"%lld\n", Binsearch (min,l)); }    return 0;}
View Code

poj3258--Two-point optimization

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.