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. Linux下搭建ZooKeeper集群

    摘要 Zookeeper是针对大型分布式系统的高可靠的协调系统.它基于对Paxos算法的实现,使该框架保证了分布式环境中数据的强一致性,也正是基于这样的特性,使得ZooKeeper解决很多分布式问题. ...

  2. ng-class动态类几种用法

    方法1.逻辑在后面的中括号里面 ng-class="{true : 'checker disabled',false : 'checker' }[selectAllButton]" ...

  3. [个人总结]pytorch中用checkpoint设置恢复,在恢复后的acc上升

    原因是因为checkpoint设置好的确是保存了相关字段.但是其中设置的train_dataset却已经走过了epoch轮,当你再继续训练时候,train_dataset是从第一个load_data开 ...

  4. C#连接Excel读取与写入数据库SQL ( 下 )

    接上期 dataset简而言之可以理解为 虚拟的 数据库或是Excel文件.而dataset里的datatable 可以理解为数据库中的table活着Excel里的sheet(Excel里面不是可以新 ...

  5. mysql内一些可以布尔盲注的查询语句

              一.left() 首先需要 use security;  这个数据库,然后进入之后再使用查询语句: 此时再使用: select left(database(),1)='s';    ...

  6. 开源大屏工具 DataGear 的使用

    记录一款好用的大屏工具,DataGear,官方标记为"开源免费的数据可视化分析平台". 其支持的数据集可以为SQL或HTTP API等,SQL支持MySQL等关系型数据库及Hive ...

  7. PHP配置 3. 配置open_basedir

    open_basedir将网站限定在指定的目录,做目录的隔离 先在php.ini中设置open_basedir: # vim /usr/local/php/etc/php.ini //搜索open_b ...

  8. 使用代码生成工具快速开发ABP框架项目

    在一般系统开发中,我们一般要借助于高度定制化的代码生成工具,用于统一代码风,节省开发时间,提高开发效率.不同的项目,它的项目不同分层的基类定义不同,我们需要在框架基类的基础上扩展我们的业务类代码,尽量 ...

  9. CSS中的块级元素,行内元素,行内块元素

    博客转载于:https://blog.csdn.net/swebin/article/details/90405950 块级元素 block 块级元素,该元素呈现块状,所以他有自己的宽度和高度,也就是 ...

  10. Just a Joke HDU - 4969(物理+积分)

    题目链接:https://vjudge.net/problem/HDU-4969#author=0 题意:一个人在圆心以V2速度追赶一个以V1的速度进行圆周运动,问在圆心的人能否在不超过D的距离追上他 ...