转载请标明出处:http://blog.csdn.net/Bule_Zst/article/details/76759525
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4004
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.
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
题意:
在一条河上,有很多石头,求出至少需要多大的 跳跃能力(一次可以跳多远)才能在小于等于m次的跳跃后到达对岸
方法:二分
首先求出答案的上界(left)与下界(right),上界就是河的宽度,下界就是相邻石头间的最大间距(因为如果你的跳跃能力小于最大间距,那你是肯定到达不了对岸的)。
之后,求出上界下界的中点(( left + right ) / 2),进行模拟过河(不断累加相邻石头之间的距离,一旦大于你的跳跃能力,就把跳跃次数加一,并重置距离为最后一次相邻石头之间的距离),最后根据过河次数更新上下界(如果次数大于m,就把下界换成mid+1,如果小于等于m,就把上界换成mid),循环直到left>=right,输出答案。
代码:
// @Team : nupt2017team12
// @Author : Zst
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
#define LL long long
#define MOD 1000000007
#define CLR(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define pb push_back
#define FOR(i,a,b) for( int i = ( a ); i <= ( b ); ++i )
const int N = 500000+7;
int l, n, m;
int store[N];
int test( int ability )
{
// cout<<ability<<endl;
int dist = 0;
int times = 0;
FOR( i, 1, n+1 ) {
dist += store[i] - store[i-1];
if( dist > ability ) {
times++;
// cout<<dist<<endl;
dist = store[i] - store[i-1];
}
}
return times+1;
}
int main()
{
// freopen( "E.txt", "r", stdin );
while( scanf( "%d%d%d", &l, &n, &m ) != EOF ) {
store[0] = 0;
store[n+1] = l;
FOR( i, 1, n ) {
scanf( "%d", store + i );
}
sort( store+1, store+n+1 );
int left = 0;
int right = 0;
FOR( i, 1, n+1 ) {
left = max( left, store[i] - store[i-1] );
}
right = l;
while( left < right ) {
int mid = left + ( right - left ) / 2;
if( test( mid ) <= m )
right = mid;
else
left = mid + 1;
// cout<<left<<" "<<right<<endl;
}
printf( "%d\n", left );
}
}
本问主要介绍:1.如何安装rust环境2.使用rustc编写Hello,world3.使用Cargo编写Hello,world
import logging # 打印日志级别 def test_logging() : logging . debug('Python debug') logging . info('Python info') logging . warning('Python warning') logging . error('Python Error') logging . critical('Python critical') test_logging()Logger是一个树形层级结构Logger。
一.说明1.Linux: CentOS72.Anaconda:Anaconda3-2020.07-Linux-x86_64.sh二.安装步骤1.软件下载进入到anaconda官网下载linux版本:https://www.anaconda.com/download/#linux(2)使用bash命令安装进入到下载目录,然后bash命令,如:bash Anaconda3-2020.07-Linux-x86_64.sh然后一直按提示操作即可。(3)配置环境变量...
一周一小步,一年一大步!欧!耶!这周我完成了软件项目的一个重要的部件--dock栏,闲话少说,先上成品!!!1.创建透明窗口要实现这样一个小窗口当然需要先创建一个QWidget类,并对QWidget的背景,窗口大小,边框等等做一些小设置,这里的背景用QPinter动态描绘上边框和背景色(具体的paintEvent代码的也是从某大师那里抄的,具体哪个,我给忘了,,,)class Dock_Win(QWidget): def __init__(self, parent=None):
不足之处,欢迎专家、同行、读者批评指正。Java的工作原理Java程序从写代码到实际运行需要经过三个步骤:编写,编译、运行。在不同的阶段,分别生成了不同类型的文件。在理解工作原理的时候,我们可以看:这个文件由谁产生,给谁使用,是什么类型的。第一个阶段,编写。这个阶段由程序员写代码(用什么写无所谓,用记事本写都可以。不过编辑器我推荐Sublime...
牛客编程巅峰赛S2第7场 - 青铜&白银&黄金今天又是拉跨操作, 又是一题选手踩坑: 子序列 与 子串战绩第一题: 牛牛爱喝酒说什么, 做什么, 模拟就可以了import java.util.*;public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * 返回牛牛能喝的最多的酒 * @param m int整型 酒单价 * @param
1.选择某张表,2.点击这个图标3.选择identity4. I 图标就可以显示出来了5.数据库增加数据的时候,就可以利用自增主键
最近在学校比较闲,终于有这么一块时间可以自由支配了,所以内心还是十分的酸爽舒畅的。当然了,罪恶的事情也是有的,比如已经连续一周没有吃早饭了,其实现在回头想想,真的不能怪我啊,因为最近的天气实在是太!冷!了!好吧为了减少赖床的罪恶感,还是学(gǎo)点(diǎn)东(shì)西(qing)好了。不说废话了,还是进入正题。进入正题这个丑陋无比的聊天室,暂时给他后面加个“v1.0”吧,毕竟也是没...
问题:Forbidden (403)CSRF verification failed. Request aborted.HelpReason given for failure: CSRF token missing or incorrect. In general, this can occur when there is a genuine Cross Si
目录1 前言2 基础参数3 密钥对生成4 签名算法4.1 预处理14.2 预处理24.3 生成签名4.4 签名验证4.5 签名验证原理5 参考资料1 前言比原链的智能合约支持国密算法的函数。SM2是国密标准的椭圆曲线加密算法,遵循以下SM2国家标准:GB/T 32918.1-2016GB/T 32918.2-2016GB/T 32918.3-2016GB/T 32...
double abc=0.6666666;NumberFormat nt = NumberFormat.getPercentInstance();//设置百分数精确度2即保留两位小数nt.setMinimumFractionDigits(2);abc = Math.abs(abc); //如果是负数,怎么转出正数 例如:-0.999 转成 0.999String format = n...
一、相关概念1、ARIMA模型是一种流行且广泛使用的时间序列预测统计方法。ARIMA是AutoRegressive Integrated Moving Average的缩写。它是一类模型,它捕获时间序列数据中的一套不同的标准时间结构。AR:自回归。一种模型,它使用观察与一些滞后观察之间的依赖关系。使用原始观察的差分(例如,从前一时间步骤的观察中减去观察值)以使时间序列静止。MA:移动平...