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 ...
随机推荐
- Cannot resolve MVC View
在搭建springboot项目时报错:Cannot resolve MVC View "index" 那是因为在pom中缺少依赖 <dependency> <gr ...
- 第48天学习打卡(CSS)
HTML + CSS +JavaScript 结构+表现+交互 HTML:结构 CSS:表现 JavaScript:交互 1什么是CSS 如何学习 1.CSS是什么 2.CSS怎么用(快速入门 ...
- [数据结构与算法-15]单源最短路径(Dijkstra+SPFA)
单源最短路径 问题描述 分别求出从起点到其他所有点的最短路径,这次主要介绍两种算法,Dijkstra和SPFA.若无负权优先Dijkstra算法,存在负权选择SPFA算法. Dijkstra算法 非负 ...
- Java 面向对象 01
面向对象·一级 面向对象思想概述 * A:面向过程思想概述 * 第一步 * 第二步 * B:面向对象思想概述 * 找对象(第一步,第二步) * C:举例 * 买煎饼果子 ...
- ORM框架 和 面向对象编程
ORM框架: 1.SQLAlchemy: - 作用 1.提供简单的规则 2.自动转换成SQL语句 - DB first/code first DB first: 手动创建数据库以及表 ...
- PHP中一些常用的安全类函数
(1) htmlspecialchars() 表单验证(验证表单中的数据是否为空以及提交的数据是否合法) htmlspecialchars() //该函数将预定义的字符转化为html实体,预定义的 ...
- 2020 年安装 FreeBSD 系统的基础视频
B 站搜索 BV14i4y137mh 包含了下载,虚拟机安装,配置 SSH 等教程. https://www.bilibili.com/video/BV14i4y137mh
- MySQL基础知识:Character Set和Collation
A character set is a set of symbols and encodings. A collation is a set of rules for comparing chara ...
- Java BasicNameValuePair怎么传数组类型的参数?
BasicNameValuePair 传数组的话可以这样传 map.put("ids[]", 1); map.put("ids[]", 2);
- C# 自定义时间进度条
这篇文章对我帮助极大,我模仿着写了两遍大概摸清楚了自定义控件的流程.https://www.cnblogs.com/lesliexin/p/13265707.html 感谢大佬 leslie_xin ...