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. Java+大数据开发——Hadoop集群环境搭建(一)

    1集群简介 HADOOP集群具体来说包含两个集群:HDFS集群和YARN集群,两者逻辑上分离,但物理上常在一起 HDFS集群: 负责海量数据的存储,集群中的角色主要有 NameNode / DataN ...

  2. shell编程中的控制判断语句

    if 单格式与嵌套 if 条件表达式;then #当条件为真时执行以下语句 命令列表 else #为假时执行以下语句 命令列表 fi if 语句也可以嵌套使用 if 条件表达式1;then if 条件 ...

  3. PL/SQL学习笔记之基本块格式与语法

    一:PL/SQL程序块 PL/SQL是一种块结构的语言,一个PL/SQL程序就是一个 代码逻辑块. PL/SQL程序由三部分构成: 1 声明 部分 使用关键字DECLARE开头,它是一个可选的部分,用 ...

  4. python3用BeautifulSoup抓取id='xiaodeng',且正则包含‘elsie’的标签

    # -*- coding:utf-8 -*- #python 2.7 #XiaoDeng #http://tieba.baidu.com/p/2460150866 #使用多个指定名字的参数可以同时过滤 ...

  5. Windows10 IIS配置PHP运行环境

    http://www.cnblogs.com/wenhainan/p/5600346.html 在Windows 8 的IIS(8.0)中搭建PHP运行环境: 一:安装IIS服务器 1.进入控制面板& ...

  6. Gradle 中 buildConfigField的巧妙应用

    当用AndroidStudio来进行Android项目开发时,build.gradle就是这个工具的核心部分,所有的依赖,debug/release设置,混淆等都在这里进行配置. 下面就主要来记录下利 ...

  7. xcode9 报错 “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift

    用xcode编译后会出现这个错误的情况: 1.使用cocopod导入第三方swift包后,swift的包是比较老的swift开发的. 2.用xcode9 打开老的swift(比如swift2.0)的工 ...

  8. 在 OC 中调用 Swift 代码

    1.在 Objective-C 项目中使用 Swift 代码 1)在 OC 项目中创建 .Swift 文件,文件中的格式为其本有的格式. 2)Xcode 提示是否创建 Objective-C brid ...

  9. C#调用存储过程详解(带返回值、参数输入输出等)

    CREATE PROCEDURE [dbo].[GetNameById] @studentid varchar(8), @studentname nvarchar(50) OUTPUT AS BEGI ...

  10. python gb2312 转换为 utf-8

    url = "" headers = { "Host":"www.chinanews.com", "User-Agent" ...