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

Sourcethe 36th ACM/ICPC Asia Regional Dalian site--online Contest

Recommendlcy: Simple Two-point: code:
#include <stdio.h>#include<queue>#include<string.h>#include<algorithm>#include<iostream>#include<queue>#include<Set>#include<vector>using namespacestd;Const intMAXN =500010;intL, N, M;intSTON[MAXN];BOOLjsintx) {    intCNT =0, last = ston[0];  for(inti =1; I <= N; i++){        if(Ston[i]-ston[i-1] >x)return false; if(Ston[i]-last >x) {CNT++; Last= Ston[i-1]; if(CNT >=m)return false; }    }    return true;}intErfen (intLintR) {    intMid, ans;  while(L <=R) {Mid= (L + r) >>1; if(JS (mid)) {ans=mid; R= Mid-1; }        ElseL= Mid +1; }    returnans;}intMain () { while(~SCANF ("%d%d%d", &l, &n, &m)) {         for(inti =1; I <= N; i++) scanf ("%d", Ston +i); ston[0] =0; Ston[n+1] =L; N++; Sort (ston, ston+ N +1); printf ("%d\n", Erfen (0, L)); }    return 0;}

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.