Hdoj 4004 The Frog ' s games (two minutes)

Source: Internet
Author: User

The Frog ' s games

Time limit:2000/1000 MS (java/others) Memory limit:65768/65768 K (java/others)
Total submission (s): 5676 Accepted Submission (s): 2732


Problem DescriptionThe 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).

Inputthe input contains several cases. The first line of all case contains three positive integer L, N, and M.
then n lines follow. Each of the stands for the distance from the starting banks to the Nth stone, and both stone appear in one place is impossible.

Outputfor each case, output an integer standing for the frog ' s ability at least they should has.

Sample INPUT6 1 2225 3 311 218

Sample Output411

Source the 36th ACM/ICPC Asia regional Dalian site--online Contest
#include <cstdio>#include<iostream>#include<algorithm>using namespacestd;Const intinf=0x3f3f3f3f ;intd[550000]; intL;intCalcintx) {    intnow=0; intCnt=0; intps=0;  while(now<L) { now+=x;  while(Now >=d[ps+1]) ps++; now=D[ps]; CNT++; }     returnCNT;} intMain () {intN, M;  while(SCANF ("%d%d%d", &l, &n, &m)! =EOF) {        intMinx =0 ;  for(intI=1; i<= N; i++) scanf ("%d", &D[i]); Sort (d+1, d+1+N); d[0]=0; d[n+1]=L; D[n+2]=INF;  for(intI=1; i<= n+1; i++)            if(Minx <d[i]-d[i-1]) Minx= d[i]-d[i-1]; intleft= Minx, right=L; intRes;  while(Left <=Right ) {            intMid= (left+right) >>1; if(Calc (mid) <=m) {res=mid; Right= mid-1; }            Elseleft= mid+1; } printf ("%d\n", RES); }    return 0;}

Hdoj 4004 The Frog ' s games (two minutes)

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.