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 ...
随机推荐
- CMDB架构需求实现
CMDB资产管理部分实现 需求 1.存储所有IT资产信息 2.数据可手动添加 3.硬件信息可自动收集 4.硬件信息可自动变更 5.可对其他系统灵活开放API 6.API接口安全认证 立业之本:定义表结 ...
- 【leetcode】Basic Calculator III
题目如下: Implement a basic calculator to evaluate a simple expression string. The expression string may ...
- 设计模式来替代if-else
前言# 物流行业中,通常会涉及到EDI报文(XML格式文件)传输和回执接收,每发送一份EDI报文,后续都会收到与之关联的回执(标识该数据在第三方系统中的流转状态).这里枚举几种回执类型:MT1101. ...
- 使用bitmap实现对一千万个无重复的正整数(范围1~1亿)快速排序
1 Bytes(字节) == 8 bit 1 KBytes == 1024 Bytes 思路: 1)申请长度为1亿的保存二进制位的数组 a, 2)通过位运算,将整数做为索引,将数组a对应的索引位置为1 ...
- case 函数两种格式
1.简单case函数 CASE sex WHEN '0' THEN '男' WHEN '1' THEN '女' ELSE '其他' END 2.case搜索函数 CASE WHEN sex = '0' ...
- win10 搜索框输入没提示
1.点击win, 手动在应用里找到Cortana(小娜) 2. 点右键->更多->应用设置,进入到下面的界面 3. 下拉到最下面,找到“重置”即可
- wannafly 练习赛11 B 假的字符串(字典树+建边找环)
链接:https://www.nowcoder.com/acm/contest/59/B 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit ...
- Floating Point Math
Floating Point Math Your language isn't broken, it's doing floating point math. Computers can only n ...
- 20165218 《网络对抗技术》Exp7 网络欺诈防范
Exp7 网络欺诈防范 基础问题回答 通常在什么场景下容易受到DNS spoof攻击 公共网络下或者同一局域网内: 在日常生活工作中如何防范以上两攻击方法 钓鱼网站 查验可信第三方 核对网站域名 查询 ...
- CNN中感受野的理解
本文摘自看完还不懂卷积神经网络“感受野”?那你来找我 作者:程序_小白链接:https://www.jianshu.com/p/9305d31962d8 一.到底什么是“感受野”(接受野Recepti ...