The Frog's Games
The Frog's Games
Problem Description
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).
Input
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.
Output
ability at least they should have.
Sample Input
6 1 2
2
25 3 3
11
2
18
Sample Output
4
11
分析:
就是一个青蛙要跳的对岸,然后河流中间有M块石头,然后最多可以跳k次,问这个青蛙最短需要跳多远才可以保证不掉下去。按照我的想法,m个石头,都被跳到的话需要跳M+1次。那么如果k >= M+1次,那就是找到两块石头之间距离最大的哪一个就可以了。但是如果k < M+1次的话呢,青蛙就需要一次跳过多的石头,M+1 - k.就可以知道青蛙需要越过多少块石头,既在多少块石头上面不能停留。所以呢,我就需要每次去遍历,找到最近的相隔一块石头的两块石头。那么我就需要循环遍历(M+1-k) * (M+1) 次左右了。这肯定不行啊,大致估计一下时间复杂度500000 * 500000,GG,肯定会超时。想了一想,想不到好办法,然后百度,说用二分,去二分所要求的跳跃能力,然后每次检验一下能不能跳过去。这样再算一下时间,500000 * log(1000000000 ),这不会超时。应该记住的 n*2 的时间优化多半是优化到n*log(n), 而log(n)的优化,多半是二分,或者一些STL的数据结构。
#include<bits/stdc++.h>
using namespace std;
const int N = ;
int ans[N];
int ll, nn, mm;
bool judge (int dis) {
int tx = , i, ty = ;
for (int i = ; i <= mm; i++) {
while (ty <= nn + && ans[ty] - ans[tx] <= dis) ty++;
ty --;
tx = ty;
}
return ty == nn + ;
}
int main () {
while (~scanf("%d %d %d", &ll, &nn, &mm)) {
for (int i = ; i <= nn; i++) {
scanf("%d", &ans[i]);
}
ans[] = ; ans[nn+] = ll;
sort(ans, ans + nn +);
int L = , R = ll;
while (L <= R) {
int mid = (L + R) >> ;
if (judge(mid)) {
R = mid - ;
} else L = mid + ;
}
printf("%d\n", L);
}
return ;
}
The Frog's Games的更多相关文章
- 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(二分答案)
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) ...
- 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
题目链接: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 ...
- 杭电 4004 The Frog's Games 青蛙跳水 (二分法,贪心)
Description The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog T ...
- HDU-4004 The Frog's Games (分治)
http://acm.hdu.edu.cn/showproblem.php?pid=4004 Problem Description The annual Games in frogs' kingdo ...
- D - The Frog's Games (二分)
The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. On ...
随机推荐
- Python 运算符Ⅳ
Python比较运算符 以下假设变量a为10,变量b为20: 以下实例演示了Python所有http://www.xuanhe.net/比较运算符的操作: 以上实例输出结果: Python赋值运算符 ...
- 参数类型*&是什么意思?
前两天摸鱼聊天的时候遇到一个问题,一个链表的函数中,有一个参数显得很奇怪 (大概是一个样子的)ListNode<T>*& l 这个参数l除了用了一个*之外还用了一个&,直觉 ...
- html audio标签 语法
html audio标签 语法 audio标签的作用是什么? 作用:<audio> 标签定义声音,比如音乐和视频或其他音频资源,使用audio标签可以不用Flash插件就可以听音乐看视频, ...
- 新手 Redis 配置笔记(windows),附下载地址
1.关于安装文件的选择 安装的时候应该下载免安装版,安装版虽然一路下一步就可以了,但是,当要修改配置文件的时候,特别痛苦,搜了两个小时,居然没有找到如何用命令修改配置文件,开放远程连接.所以对于第一次 ...
- Python爬虫黑科技(经验)
"作为一名爬虫工程师,你最需要关注的,是数据的来源" 原文:https://www.jb51.net/article/90114.htm 霍夫曼编码压缩算法 1.最基本的抓站 ...
- JMS学习七(ActiveMQ之Topic的持久订阅)
非持久化订阅持续到它们订阅对象的生命周期.这意味着,客户端只能在订阅者活动时看到相关主题发布的消息.如果订阅者不活动,它会错过相关主题的消息.如果花费较大的开销,订阅者可以被定义为durable(持久 ...
- BZOJ 1859 Luogu P2589 [ZJOI2006]碗的叠放 (计算几何)
woc, 13年前的ZJOI就这么毒瘤的嘛... 题目链接: (bzoj)https://www.lydsy.com/JudgeOnline/problem.php?id=1859 (luogu)ht ...
- SQL Server服务起不了
转载 MSSQLSERVER服务无法启动的解决方案 1.IP地址配置不正确: 打开 Microsoft SQL Server 2005配置工具下的SQL Server Configuration ...
- sqli-lab(15)
要考四级了 翻译过来就是 基于时间的单引号盲注 0X01盲注 的了解 https://www.cnblogs.com/ldhbetter/p/9201840.html 这里写的清清楚楚 A 先拆解长度 ...
- pkill精确匹配进程名称
kill对应的是PID,pkill对应的是command pgrep -l mycmd 注意命令名称过长pkill匹配进程名称是有可能被截取. pkill -9 '^pu_simulatio(n$|n ...