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 ...
随机推荐
- 正则表达式匹配${key}并在Java中使用
1.正则表达式匹配${key} \$\{([a-z]+)\} 能够匹配字符串中以${key}形式的文本(其中key为小写应为字母) .*\$\{([a-z]+)\}.* 可以用来检测文本中是否有${k ...
- Java文件字节流
//输出和输入流 package com.kangkang.IO; import com.sun.xml.internal.ws.util.xml.CDATA; import java.io.File ...
- FakeTaobaoDeepLink - 复制淘宝deeplink来拦截淘宝广告的自动拉起
Fake Taobao Deeplink 复制 ** com.taobao.tao.welcome.Welcome ** 的intent-filter来拦截误触广告后自动拉起淘宝app 完整工程 Gi ...
- 基于Hi3559AV100的视频采集(VDEC-VPSS-VO)整体框图设计
下面给出基于Hi3559AV100的视频采集整体设计,具体设计将在后续给出: 图形采集端整体设计 Hi3559AV100软件程序按结构划分可分为4层,第一层是硬件驱动层,第二层是操作系统层,第三层是媒 ...
- Salesforce LWC学习(三十一) Quick Action适配
本篇参考:https://www.lightningdesignsystem.com/components/modals/ 随着salesforce lwc的优化,越来越多的项目从aura转到了lwc ...
- PAT-1043(Is It a Binary Search Tree)JAVA实现
Is It a Binary Search Tree PAT-1043 主要涉及到根据前序遍历序列片段是否是一颗二叉树,这里有一个小tip就是插入序列就是二叉树的前序遍历序列. 第二个是会对排序二叉树 ...
- ASP.NET Core重复读取Request.Body
//HttpContext context.Request.EnableRewind(); //创建缓冲区存放Request.Body的内容,从而允许反复读取Request.Body的Stream u ...
- Redis单机数据库的实现原理
本文主要介绍Redis的数据库结构,Redis两种持久化的原理:RDB持久化.AOF持久化,以及Redis事件分类及执行原理.最后,分别介绍了单机班Redid客户端和Redis服务器的使用和实现原理. ...
- 初探JavaScript原型链污染
18年p师傅在知识星球出了一些代码审计题目,其中就有一道难度为hard的js题目(Thejs)为原型链污染攻击,而当时我因为太忙了(其实是太菜了,流下了没技术的泪水)并没有认真看过,后续在p师傅写出w ...
- FreeRedis分布式锁实现以及使用
前言 今日上班听到同事在准备面试题分布式锁(准备溜溜球),随即加入了群聊复习了一波,于是有了这篇小作文. 场景 本文中的演示 DEMO, 以下订单减库存为例. 无锁裸奔表现 示例代码: 先来模拟一个库 ...