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 ...
随机推荐
- MySQL数据表
创建数据表 CREATE TABLE IF NOT EXISTS ([列名column][类型type][约束可选]) 查看数据表结构 DESC <表名> 修改数据表结构 ALTER ...
- Ubuntu下安装CUDA8.0及nvidia驱动
参考:https://blog.csdn.net/qq_35379989/article/details/80147630 cuda的历史版本下载地址:https://developer.nvidia ...
- Vue-Router的简单使用
Vue-Router的最简单使用 1.先注册路由 2.将路由注册到VM组件中 3.定义组件 4.页面定义跳转路径 <!DOCTYPE html> <html> <head ...
- 织梦dedecms自定义表单导出到excel教程
不写死任何字段,不写死任何东西,修改2个文件,让织梦自定义表单自由导出到Excel表格里. 添加教程 1.\dede\templets\diy_main.htm 找到 前台预览</a> 在 ...
- sh_11_九九乘法表
sh_11_九九乘法表 # 1. 打印 9 行小星星 row = 1 while row <= 9: col = 1 while col <= row: # print("*&q ...
- create-react-app 构建的项目使用 mobx (说到底就是为了使用装饰器语法对 babel 做些配置
在 create-react-app 命令行构建的 React 项目中使用 Mobx 会出现如下警告: Support for the experimental syntax 'decorators- ...
- 【python学习之五】自定义函数实现用 Python 发送电子邮件
前言 之前论坛里有人发过关于发送邮件的帖子,设计器也有关于发送邮件的控件.我这里再次重复,希望能有帮到大家的地方. 信息准备 发送邮件前必须准备好一些基本信息,例如发件人邮箱地址.发件人邮箱密码.收件 ...
- AttributeError: module 'datetime' has no attribute 'now'
在用时间转化时,一直报AttributeError: module 'datetime' has no attribute 'now', 我用的 import datetime datetime ...
- [BZOJ1059]:[ZJOI2007]矩阵游戏(二分图匹配)
题目传送门 题目描述 小Q是一个非常聪明的孩子,除了国际象棋,他还很喜欢玩一个电脑益智游戏——矩阵游戏.矩阵游戏在一个N×N黑白方阵进行(如同国际象棋一般,只是颜色是随意的).每次可以对该矩阵进行两种 ...
- ENGINE =MyISAM DEFAULT CHARACTER SET latin1 COLLATE latin1_general_cs AUTO_INCREMENT=0; 什么意思
ENGINE =MyISAM //表类型为myisam插写比较快 DEFAULT CHARACTER SET latin1//默认字符为latin1 COLLATE latin1_general ...