Hdu 4004 The Frog ' s games

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4004

The annual games in Frogs ' kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes-to-jump. The width of the river is L (1<= l <= 1000000000). There is n (0<= n <= 500000) stones lined up on a straight line from one side to the other side of the river. The frogs can only jump through the river, but they can land on the stones. If they fall into the river, they
is out . The frogs is asked to jump at a most m (1<= m <= n+1) times. Now the frogs want to know if they want to jump across the river, at least what ability should they has. (That's the frog ' s longest jump distance). Test Instructions: A long L river has n stones, the frog in the original position by the most jumps m times (each time must fall on the stone or ashore) to pass this river, the frog farthest bounce ability of the minimum value. solution: Generally see the minimum required maximum value of what, will immediately associate to the binary search. This problem can be done with two points. The value of the farthest bounce ability of the frog, judging whether the solution is effective by judging whether the most jump M-times can cross the river, and then ask for the minimum.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <cmath>6#include <algorithm>7 #defineINF 0x7fffffff8 using namespacestd;9 Const intmaxn=500000+ -;Ten intAN[MAXN]; One intl,n,m; A intisOKintlen) - { -     intstep=0; the     int  from=0; -     intI=1; -      while( from<l && i<=n+1) -     { +         intj=i; -          while(an[i]- from<=len && i<=n+1) {j=i; i++ ; } +Step + + ; A          from=An[j]; atI=J; -         if(step>m)return 0; -     } -     return 1; - } - intMain () in { -      while(SCANF ("%d%d%d", &l,&n,&m)! =EOF) to     { +          for(intI=1; i<=n; i++) scanf ("%d",&an[i]); -an[n+1]=L; theSort (an+1, an+n+1+1); *         intL=0, r=inf; $         intans=0;Panax Notoginseng          while(l<=R) -         { the             intMid= (l+r) >>1; +             if(isOK (mid)) {ans=mid; r=mid-1 ; } A             ElseL=mid+1 ; the         } +printf"%d\n", ans); -     } $     return 0; $}

Hdu 4004 The Frog ' s games

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.