编程介的小学生 2017-11-19 09:39 采纳率: 20.5%
浏览 713
已结题

The Frog's Games

Problem Description
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 over the river. The width of the river is L (1<= L <= 1000000000). There are n (0<= n <= 500000) stones lined up in 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
are out. The frogs was asked to jump at 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 have. (That is the frog's longest jump distance).

Input
The input contains several cases. The first line of each case contains three positive integer L, n, and m.
Then n lines follow. Each stands for the distance from the starting banks to the nth stone, two stone appear in one place is impossible.

Output
For each case, output a integer standing for the frog's ability at least they should have.

Sample Input
6 1 2
2
25 3 3
11
2
18

Sample Output
4
11

  • 写回答

1条回答 默认 最新

  • $(X) 2018-07-17 15:12
    关注
    /*from:  https://www.cnblogs.com/huangxf/p/4127157.html*/
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<algorithm>
    #define inf 0x7fffffff
    using namespace std;
    const int maxn=500000+100;
    int an[maxn];
    int L,n,m;
    int isok(int len)
    {
        int step=0;
        int from=0;
        int i=1;
        while (from<L && i<=n+1)
        {
            int j=i;
            while (an[i]-from<=len && i<=n+1) {j=i ;i++ ; }
            step ++ ;
            from=an[j];
            i=j;
            if (step>m) return 0;
        }
        return 1;
    }
    int main()
    {
        while (scanf("%d%d%d",&L,&n,&m)!=EOF)
        {
            for (int i=1 ;i<=n ;i++) scanf("%d",&an[i]);
            an[n+1]=L;
            sort(an+1,an+n+1+1);
            int l=0,r=inf;
            int ans=0;
            while (l<=r)
            {
                int mid=(l+r)>>1;
                if (isok(mid)) {ans=mid ;r=mid-1 ; }
                else l=mid+1 ;
            }
            printf("%d\n",ans);
        }
        return 0;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名