D - The Frog's Games (二分)
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 (二分)的更多相关文章
- HDU 4004 The Frog's Games(二分答案)
The Frog's Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) ...
- 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) ...
- HDU 4004 The Frog's Games(二分)
题目链接 题意理解的有些问题. #include <iostream> #include<cstdio> #include<cstring> #include< ...
- The Frog's Games(二分)
The Frog's Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) ...
- HDUOJ----4004The Frog's Games(二分+简单贪心)
The Frog's Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) ...
- The Frog's Games
The Frog's Games Problem Description The annual Games in frogs' kingdom started again. The most famo ...
- HDU 4004 The Frog's Games(2011年大连网络赛 D 二分+贪心)
其实这个题呢,大白书上面有经典解法 题意是青蛙要跳过长为L的河,河上有n块石头,青蛙最多只能跳m次且只能跳到石头或者对面.问你青蛙可以跳的最远距离的最小值是多大 典型的最大值最小化问题,解法就是贪心 ...
- hdu 4004 The Frog's Games
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4004 The annual Games in frogs' kingdom started again ...
- H - The Frog's Games
The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. On ...
随机推荐
- Go的包
目录 go的包 一.包的创建规则 二.包的导入规则 三.包的函数调用 go的包 一.包的创建规则 一个包就是一个文件夹. 同一个包(文件夹)下,所有go文件都只能用同一个package,也就是每个文件 ...
- 手把手教你手写一个最简单的 Spring Boot Starter
欢迎关注微信公众号:「Java之言」技术文章持续更新,请持续关注...... 第一时间学习最新技术文章 领取最新技术学习资料视频 最新互联网资讯和面试经验 何为 Starter ? 想必大家都使用过 ...
- 5G组网方案:NSA和SA
目录 5G组网的8个选项 独立组网(SA) 选项1 选项2 选项5 选项6 总结 非独立组网(NSA) 选项3系列 选项3 选项3a 选项3x 选项7系列 选项4系列 选项8 演进路线 5G组网的8个 ...
- 180. 连续出现的数字 + MySql + 连续出现数字 + 多表联合查询
180. 连续出现的数字 LeetCode_MySql_180 题目描述 代码实现 # Write your MySQL query statement below select distinct t ...
- SpringCloud-服务与注册
SpringCloud- Eureka服务注册与发现 1.概述 springcloud是一个非常优秀的微服务框架,要管理众多的服务,就需要对这些服务进行治理,管理每个服务与每个服务之间的依赖关系,可以 ...
- Windows-Redis占用C盘系统空间
发现redis在电脑死机蓝屏的情况下,就是非正常退出redis会导致redis的缓存文件不会回收,占用系统空间, 下次在启动的时候,会再次创建一个10G多的缓存文件,极度占用磁盘空间. 现说明解决办法 ...
- FreeBSD 镜像站问题 @2021
主要问题在于官方无论如何也不开放 rsync 且不接受镜像站的官方二级镜像申请. 多次联系均无二次联系,如邮件列表,大概五次,其中三次回应,两次无回应.其主要回复内容为"深表歉意,但台湾地区 ...
- VScode 自定义用户代码块
1定义html中的vue 见地址 https://blog.csdn.net/qq_40191093/article/details/82915028 2 https://www.cnblogs.c ...
- net core 中间件和管道
1.中间件 是处理请求和响应的组件(代码段,一段处理逻辑),这个处理逻辑是以"前一个请求处理逻辑"为输入,并经过中间件自己的处理后,返回一个"新的请求处理逻辑" ...
- 一文读懂SuperEdge拓扑算法
前言 SuperEdge service group 利用 application-grid-wrapper 实现拓扑感知,完成了同一个 nodeunit 内服务的闭环访问 在深入分析 applica ...