H - The Frog's Games
The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes to jump over the river. The width of the river is L (1<= L <= 1000000000). There are n (0<= n <= 500000) stones lined up in a straight line from one side to the other side of the river. The frogs can only jump through the river, but they can land on the stones. If they fall into the river, they
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
The 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.
Output
For 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
青蛙要在要求步数能过河,求青蛙最小的最大跳跃能力,二分;因为这个判断比较麻烦,弄错好久
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define pb push_back
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<map>
#define for(i,a,b) for(int i=a;i<b;i++)
typedef __int64 ll;
typedef long double ld;
typedef double db;
const ll mod=1e12+100;
const db e=exp(1);
using namespace std;
const double pi=acos(-1.0);
int a[500005],l;
int n,m;
bool judge(int mid)
{
int ans=0,last=0;
if(a[0]>mid) return false;
for(i,0,n)
{
if(a[i+1]-a[i]>mid) return false;
if(a[i]-last==mid)
{
ans++;
last=a[i];
}else if(a[i+1]-last>mid)
{
ans++;
last=a[i];
}
}
ans++;
if(ans<=m) return true;
return false;
}
int main()
{
// freopen("output1.txt", "r", stdin);
while(~sf("%d%d%d",&l,&n,&m))
{
int left=0,right=l,mid;
for(i,0,n)
sf("%d",&a[i]);
a[n]=l;
sort(a,a+n);
while(right-left>1)
{
mid=(left+right)/2;
if(judge(mid))
right=mid;
else
left=mid;
}
while(!judge(left)) left++;
pf("%d\n",left);
}
return 0;
}
H - 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) ...
- 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(二分答案)
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 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 ...
- hdu 4004 The Frog's Games
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4004 The annual Games in frogs' kingdom started again ...
- 杭电 4004 The Frog's Games 青蛙跳水 (二分法,贪心)
Description The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog T ...
随机推荐
- [leetcode]Largest Rectangle in Histogram @ Python
原题地址:https://oj.leetcode.com/problems/largest-rectangle-in-histogram/ 题意: Given n non-negative integ ...
- logstash 学习小记
logstash 学习小记 标签(空格分隔): 日志收集 Introduce Logstash is a tool for managing events and logs. You can use ...
- ZOJ 3827 Information Entropy 水
水 Information Entropy Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge Informati ...
- OpenCV 学习笔记 05 人脸检测和识别
本节将介绍 Haar 级联分类器,通过对比分析相邻图像区域来判断给定图像或子图像与已知对象是否匹配. 本章将考虑如何将多个 Haar 级联分类器构成一个层次结构,即一个分类器能识别整体区域(如人脸) ...
- Handlebars模板引擎之高阶
Helpers 其实在Handlebars模板引擎之进阶我想说if else的功能的,可是由于这个功能在我的开发中我觉的鸡肋没啥用,就直接不用了. 因为if else只能进行简单判断,如果条件参数返回 ...
- latex学习(四)tlmgr
官网说明文档:https://tug.org/texlive/doc/tlmgr.html,2018版已经被冻结了,所以tlmgr也不会更新了,要等到下一个大的版本才能更新. 1.用tlmgr查看已经 ...
- C++11 右值引用和转移语义
新特性的目的 右值引用 (Rvalue Referene) 是 C++ 新标准 (C++11, 11 代表 2011 年 ) 中引入的新特性 , 它实现了转移语义 (Move Sementics) 和 ...
- HttpPost请求将json作为请求体传入的简单处理方法
https://www.cnblogs.com/mambahyw/p/7875142.html **************************************************** ...
- Error:java: invalid source release 无效的源发行版: 8
原因:这是由于jdk的版本与项目的要求不一致造成的,如果是maven项目,首先查看一下pom.xml,以我的项目为例: 从其中可以看出要求的编译插件为1.8版本,而我本机上安装的jdk为1.7版本,因 ...
- ipv6禁用导致rpcbind服务启动失败实例
ipv6禁用导致rpcbind服务启动失败实例 昨天在做服务器磁盘分区扩容的时候出现过一个服务启动的问题,在此记录.情景再现:前天晚上申请做磁盘扩容,得到批准后,昨天早上5点开始做停机调整维护 ...