POJ 3258 River Hopscotch (two-point search)

Source: Internet
Author: User

Description

Every year the cows hold anEventFeaturing a peculiar version of hopscotch that involves carefully jumping fromRock to RockinchA river. The excitement takes place on aLong, Straight River with a rock at the start and another rock at the end, L units away fromThe Start (1≤l≤1, the, the, the). Along the river between the starting and ending Rocks, N (0≤n≤ -, the) more rocks appear, each at an integral distance Di fromThe Start (0< Di <L). To play the game, each cowinchTurn starts at the starting rock and tries to reach the finish at the ending rock, jumping only fromRock to Rock. Of course, less agile cows never make it to the final rock, ending up insteadinchThe River . Farmer John isProud of his cows and watches This EventEach year. But asTime goes by, he tires of watching the timid cows of the other farmers limp across the ShortDistances between rocks placed too closely together. He plans to remove several rocksinchorder to increase the shortest distance a cow would has 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 optimalSetof M Rocks.

Input

1: three space-2.. n+1 is from the starting rock. No Rocks share the same position.

Output

1  is the maximum of the shortest distance a cow have to jump after removing M rocks

Sample Input

 - 5 2 2  -  One  +  -

Sample Output

4

Hint

2  from 0 2 2  -  is 4 (from + from).

Source

Usaco 2006 December Silver
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <map>6#include <Set>7 using namespacestd;8 #defineN 500069 intDis[n];Ten intl,n,m; One BOOLSolveintMin_dis) { A     intlast=0; -     intCnt=0; -      for(intI=1; i<=n+1; i++){ the         if(Dis[i]-dis[last]<=min_dis) cnt++; -         Elselast=i; -     } -  +     if(cnt>m)return true; -     return false; +  A } at intMain () - { -  -      while(SCANF ("%d%d%d", &l,&n,&m) = =3){ -          for(intI=1; i<=n;i++){ -scanf"%d",&dis[i]); in         } -  to         if(n==L) { +printf"%d\n", L); -             Continue; the         } *  $dis[0]=0;Panax Notoginsengdis[n+1]=L; -Sort (dis+1, dis+n+1); the         intlow=0; +         intHigh=L; A          while(low<High ) { the             intMid= (Low+high) >>1; +             if(Solve (mid)) { -High=mid; $             } $             Else{ -Low=mid+1; -             } the         } -printf"%d\n", low);Wuyi     } the     return 0; -}
View Code

POJ 3258 River Hopscotch (two-point search)

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.