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

青蛙要在要求步数能过河,求青蛙最小的最大跳跃能力,二分;因为这个判断比较麻烦,弄错好久

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define pb push_back
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<map>
#define for(i,a,b) for(int i=a;i<b;i++)
typedef __int64 ll;
typedef long double ld;
typedef double db;
const ll mod=1e12+100;
const db e=exp(1);
using namespace std;
const double pi=acos(-1.0);
int a[500005],l;
int n,m;
bool judge(int mid)
{
int ans=0,last=0;
if(a[0]>mid) return false;
for(i,0,n)
{
if(a[i+1]-a[i]>mid) return false;
if(a[i]-last==mid)
{
ans++;
last=a[i];
}else if(a[i+1]-last>mid)
{
ans++;
last=a[i];
}
}
ans++;
if(ans<=m) return true;
return false;
}
int main()
{
// freopen("output1.txt", "r", stdin);
while(~sf("%d%d%d",&l,&n,&m))
{
int left=0,right=l,mid;
for(i,0,n)
sf("%d",&a[i]);
a[n]=l;
sort(a,a+n);
while(right-left>1)
{
mid=(left+right)/2;
if(judge(mid))
right=mid;
else
left=mid;
}
while(!judge(left)) left++;
pf("%d\n",left);
}
return 0;
}

H - The Frog's Games的更多相关文章

  1. The Frog's Games(二分)

    The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) ...

  2. The Frog's Games

    The Frog's Games Problem Description The annual Games in frogs' kingdom started again. The most famo ...

  3. HDU 4004 The Frog's Games(二分答案)

    The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) ...

  4. HDUOJ----4004The Frog's Games(二分+简单贪心)

    The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) ...

  5. HDU 4004 The Frog's Games(二分+小思维+用到了lower_bound)

    The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) ...

  6. HDU-4004 The Frog's Games (分治)

    http://acm.hdu.edu.cn/showproblem.php?pid=4004 Problem Description The annual Games in frogs' kingdo ...

  7. D - The Frog's Games (二分)

    The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. On ...

  8. hdu 4004 The Frog's Games

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4004 The annual Games in frogs' kingdom started again ...

  9. 杭电 4004 The Frog's Games 青蛙跳水 (二分法,贪心)

    Description The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog T ...

随机推荐

  1. 全景分割pipeline搭建

    全景分割pipeline搭建 整体方法使用语义分割和实例分割结果,融合标签得到全景分割结果: 数据集使用:panoptic_annotations_trainval2017和cityscapes; p ...

  2. 【ZH奶酪】如何用Python实现编辑距离?

    1. 什么是编辑距离? 编辑距离(Edit Distance),又称Levenshtein距离,是指两个字串之间,由一个转成另一个所需的最少编辑操作次数.许可的编辑操作包括将一个字符替换成另一个字符, ...

  3. GDAL对TIF创建内建金字塔一个问题

    gdalwarp输出tif图像的时候,默认如果没有使用BIGTIFF=YES选项,则会根据输出影像的大小进行判断,低于4G则不适用bigtiff格式. 对于非bigtiff图像,如果这时候使用gdal ...

  4. 基于Centos搭建个人 Leanote 云笔记本

    系统要求:CentOS 7.2 64 位操作系统 下载启动 MongoDB Leanote 依赖 MongoDB 作为数据存储,下面开始安装 MongoDB: 下载 MongoDB 进入 /home  ...

  5. 基于Centos搭建Laravel 环境搭建

    系统要求:CentOS 7.2 64 位操作系统 安装 Laravel Laravel 简介 Laravel 是一套简洁.优雅的 PHP Web 开发框架.它可以让你从面条一样杂乱的代码中解脱出来:它 ...

  6. Redis集群搭建(转自一菲聪天的“Windows下搭建Redis集群”)

    配置Redis参考:http://blog.csdn.net/zsg88/article/details/73715947 使用Ruby配置集群参考:https://www.cnblogs.com/t ...

  7. mariadb(MySql)设置远程访问权限

    [问题]mariadb(MySql)安装之后,本地连接mysql是可以的,但是远程的机器不能连接和访问. [解决]修改mysql远程连接的ip限制配置. [步骤]1.本地mysql客户端连接mysql ...

  8. [转]关于ios 推送功能的终极解决

    刚刚做了一个使用推送功能的应用 遇到了一些问题整的很郁闷 搞了两天总算是弄明白了 特此分享给大家 本帖 主要是针对产品发布版本的一些问题 综合了网上一些资料根据自己实践写的 不过测试也可以看看 首先要 ...

  9. Atitit 提升开发进度大方法--高频功能与步骤的优化 类似性能优化

    Atitit 提升开发进度大方法--高频功能与步骤的优化 类似性能优化 1. 通用功能又可以组合成crud模块1 1.1. 查询(包括步骤,发送查询dsl,通讯返回结果,绑定到表格控件)2 1.2. ...

  10. Multiplication of numbers

    Questin: There is an array A[N] of N numbers. You have to compose an array Output[N] such that Outpu ...