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

InputThe 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.OutputFor 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

题意:第一次提交的时候因为理解错题意WA,

一只青蛙要过一条河,给出了河的宽度,石头距离岸边的位置,和规定的调的步数

求青蛙最远要调的距离的最小值

AC代码:

 1 #include<stdio.h>
2 #include<algorithm>
3 #include<string.h>
4 using namespace std;
5
6 int l, n, m, a[500005];
7 int left, mid, right;
8
9 bool solve(int x)
10 {
11 int last = 0;
12 int num = 0;
13 for(int i = 0; i <= n;)
14 {
15 if(a[i] <= last+mid)
16 i++;
17 else
18 {
19 if(last == a[i-1])
20 return false;
21 last = a[i-1];
22 num++;
23 }
24 }
25 num++; //跳到最后一块石头上后还要再跳一下才能到达岸上;
26 return num <= m;
27 }
28
29 int main()
30 {
31 int ans;
32 while(~scanf("%d%d%d", &l, &n, &m))
33 {
34 memset(a, 0, sizeof(a));
35 for(int i = 0; i < n; i++)
36 scanf("%d", &a[i]);
37 a[n] = l;
38 sort(a, a+n+1);
39
40 left = 1;
41 right = l;
42
43 while(left <= right)
44 {
45 mid = (left + right) / 2;
46 if(solve(mid))
47 {
48 ans = mid;
49 right = mid - 1;
50 }
51 else
52 left = mid + 1;
53 }
54 printf("%d\n", ans);
55 }
56
57 return 0;
58 }

D - The Frog's Games (二分)的更多相关文章

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

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

  2. 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) ...

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

    题目链接 题意理解的有些问题. #include <iostream> #include<cstdio> #include<cstring> #include< ...

  4. The Frog's Games(二分)

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

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

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

  6. The Frog's Games

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

  7. HDU 4004 The Frog's Games(2011年大连网络赛 D 二分+贪心)

    其实这个题呢,大白书上面有经典解法  题意是青蛙要跳过长为L的河,河上有n块石头,青蛙最多只能跳m次且只能跳到石头或者对面.问你青蛙可以跳的最远距离的最小值是多大 典型的最大值最小化问题,解法就是贪心 ...

  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. H - The Frog's Games

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

随机推荐

  1. hive中更改表impala中不能生效

    hive中的更新或者新建表impala 不能实时更新 Impala是基于Hive的大数据实时分析查询引擎,直接使用Hive的元数据库Metadata,意味着impala元数据都存储在Hive的meta ...

  2. .net 开源模板引擎jntemplate 实战演习:基础篇之入门

    一.简介 模板引擎是Web开发中非常重要的一环,它负责将页面上的动态内容呈现出最终的结果展现给前端用户,在asp.net mvc中,我们最熟悉的就是Razor了,作为官方的视图引擎(视图引擎不等同于模 ...

  3. 常见 git 需求整理(持续更新中)

    首发于 语雀文档 突然感觉自己对 git 还是挺熟悉的,因为团队里新来的七八号应届生来问我 git 问题,基本没有答不上的情况,但为了能更好地对知识进行整理,还是记录一下为好. (希望能)持续更新.. ...

  4. CloudQuery v1.3.4 版本更新

    Hello,大家好久不见! 上一个版本(v1.3.3)发布已是春节前的事情了,此次 v1.3.4 是 CloudQuery 社区版在辛丑牛年的第一个版本发布.本次更新增加了新功能,优化了原有功能点.同 ...

  5. FreeBSD ports 多线程编译

    FreeBSD ports 多线程编译FORCE_MAKE_JOBS=yesMAKE_JOBS_NUMBER=4写入/etc/make.conf没有就新建.4是处理器核心数,不知道就别改.

  6. 树莓派4刷FreeBSD

    树莓派4可以刷FreeBSD了.需要替换boot文件.​加群获得文件QQ交流群817507910.

  7. JS获取时间日期常用方法

    1 当前时间: new Date() 2 当前周: function getCurrentWeek() { var date = new Date() var beginDate = new Date ...

  8. Kubernetes 实战 —— 03. pod: 运行于 Kubernetes 中的容器

    介绍 pod P53 pod 是 Kubernetes 中最为重要的核心概念,而其他对象仅仅用于 pod 管理. pod 暴露或被 pod 使用. pod 是一组并置的容器,代表了 Kubernete ...

  9. MySQL入门(2)——存储引擎

    MySQL入门(2)--存储引擎 查询MySQL支持的存储引擎 查询全部支持的引擎: show engines; ";"可以使用"\g"等价替换,而使用&quo ...

  10. Flutter学习简记

    StatefulWidget和StatelessWidget StatefulWidget : 具有可变状态的窗口部件,也就是你在使用应用的时候就可以随时变化,比如我们常见的进度条,随着进度不断变化. ...