当前位置: 首页 > 编程日记 > 正文

洛谷P3572 [POI2014]PTA-Little Bird

P3572 [POI2014]PTA-Little Bird

题目描述

In the Byteotian Line Forest there are nn trees in a row.

On top of the first one, there is a little bird who would like to fly over to the top of the last tree.

Being in fact very little, the bird might lack the strength to fly there without any stop.

If the bird is sitting on top of the tree no. i, then in a single flight leg it can fly toany of the trees no. i+1,i+2,\cdots,i+ki+1,i+2,,i+k, and then has to rest afterward.

Moreover, flying up is far harder to flying down. A flight leg is tiresome if it ends in a tree at leastas high as the one where is started. Otherwise the flight leg is not tiresome.

The goal is to select the trees on which the little bird will land so that the overall flight is leasttiresome, i.e., it has the minimum number of tiresome legs.

We note that birds are social creatures, and our bird has a few bird-friends who would also like to getfrom the first tree to the last one. The stamina of all the birds varies,so the bird's friends may have different values of the parameter kk.

Help all the birds, little and big!

从1开始,跳到比当前矮的不消耗体力,否则消耗一点体力,每次询问有一个步伐限制,求每次最少耗费多少体力

输入输出格式

输入格式:

There is a single integer nn (2\le n\le 1\ 000\ 0002n1 000 000) in the first line of the standard input:

the number of trees in the Byteotian Line Forest.

The second line of input holds nn integers d_1,d_2,\cdots,d_nd1​​,d2​​,,dn​​ (1\le d_i\le 10^91di​​109​​)separated by single spaces: d_idi​​ is the height of the i-th tree.

The third line of the input holds a single integer qq (1\le q\le 251q25): the number of birds whoseflights need to be planned.

The following qq lines describe these birds: in the ii-th of these lines, there is an integer k_iki​​ (1\le k_i\le n-11ki​​n1) specifying the ii-th bird's stamina. In other words, the maximum number of trees that the ii-th bird can pass before it has to rest is k_i-1ki​​1.

输出格式:

Your program should print exactly qq lines to the standard output.

In the ii-th line, it should specify the minimum number of tiresome flight legs of the ii-th bird.

输入输出样例

输入样例#1:
9
4 6 3 6 3 7 2 6 5
2
2
5
输出样例#1:
2
1

说明

从1开始,跳到比当前矮的不消耗体力,否则消耗一点体力,每次询问有一个步伐限制,求每次最少耗费多少体力

#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 1000010
using namespace std;
int n,a[maxn],dp[maxn],q;
int main(){scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);scanf("%d",&q);int limit;for(int i=1;i<=q;i++){scanf("%d",&limit);memset(dp,127/3,sizeof(dp));dp[1]=0;for(int i=2;i<=n;i++){for(int j=i-1;i-j<=limit&&j>=1;j--){if(a[j]>a[i])dp[i]=min(dp[i],dp[j]);else dp[i]=min(dp[i],dp[j]+1);}}printf("%d\n",dp[n]);}
}
40分 暴力dp
/*非常标准的单调队列优化dp维护两个单调性,首先是dp[]单调递减,其次是a[]单调递增 
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 1000010
using namespace std;
int n,op,a[maxn],dp[maxn],q[maxn],h,t;
int main(){scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);scanf("%d",&op);int limit;for(int i=1;i<=op;i++){scanf("%d",&limit);h=1,t=1;dp[1]=0;q[1]=1;for(int i=2;i<=n;i++){while(t-h>=0&&i-q[h]>limit)h++;dp[i]=dp[q[h]]+(a[q[h]]<=a[i]);while(t-h>=0&&((dp[q[t]]>dp[i])||(dp[q[t]]==dp[i]&&a[q[t]]<a[i])))t--;q[++t]=i;}printf("%d\n",dp[n]);}
}
100分 单调队列优化dp

转载于:https://www.cnblogs.com/thmyl/p/7494621.html

相关文章:

ps aux详解(进程状态说明)

linux上进程有5种状态: 1. 运行(正在运行或在运行队列中等待) 2. 中断(休眠中, 受阻, 在等待某个条件的形成或接受到信号) 3. 不可中断(收到信号不唤醒和不可运行, 进程必须等待直到有中断发生) 4. 僵死(进程已终止, 但进程描述符存在, 直到父进程调用wait4()系统调用后释放) 5…

小程序云开发 一开通云开发,给数据库添加一条记录

先来一个给云数据库添加一条数据库记录的代码&#xff1a; wx.cloud.init({env:school-5k07l})const db wx.cloud.database()const school db.collection(school_db)//school_db是数据库记录的名称&#xff0c;相当于MYSQL中数据库的表的名字school.add({// data 字段表示需新…

spring vertx_如何在Spring设置Vertx

spring vertxby Rick Lee李瑞克(Rick Lee) 如何在Spring设置Vertx (How to set up Vertx in Spring) Spring is probably the most popular framework in the Java space. We all love its dependency injection and all that autowired/configuration magic. It makes unit t…

-lt -gt -ge -le -eq的意义

脚本如下:#!/bin/bashx0while [ $x -lt 10 ]doecho $xxecho "$x1" | bcdone请问这里的-lt是什么意思&#xff0c;请大家指点一二&#xff0c;谢谢。 -lt less than 小于-gt great than 大于-ge great equal 大于等于-le less equal 小于等于-eq equal…

elasticsearch5.5.2环境搭建

运行elasticsearch5.5.2需要jdk1.8版本以上 1.elasticsearch可以去官网或github下载&#xff0c;window系统推荐zip压缩版 2.解压后 进入bin目录运行elasticsearch.bat启动服务 3.访问localhost:9500测试是否成功 4.安装中文分词插件&#xff1a;https://github.com/medcl/elas…

React useState,useEffect ,Hook是什么?什么是副作用?

初步接触 React 中的同学可能会对 useState,useEffect ,Hook,副作用 这些命名比较陌生,一起来了解一下。 Hook是什么? Hook 是钩子,我理解他是一个概念,在不使用class(使用函数)定义一个组件的时候,能用到一些 React 的钩子函数;React 内置了一些像 useState 这样…

塞尔达传说顺序_编码《塞尔达传说》克隆图例

塞尔达传说顺序In this lecture from Colton Ogden, you can learn game development principles by coding a classic Legend of Zelda clone in Lua. The principles you learn can apply to any programming language and any game.在科尔顿奥格登(Colton Ogden)的演讲中&am…

Scrum卡片层次图

对照国内的项目管理软件禅道&#xff0c;可以好好感受一下&#xff0c;何为Scrum。 看板则一定要是实物&#xff0c;才有感觉。 转载于:https://www.cnblogs.com/x3d/p/7500801.html

Linux 中打开tomcat的startup.sh 没有显示successed的方法。

网上下载了tomcat的压缩包&#xff0c;解压到home目录下&#xff0c;然后进入到bin目录下&#xff0c;输入./startup.sh 下面显示如下&#xff1a; 并没有显示successed&#xff0c;但是实际上已经成功启动了tomcat。 去网页上&#xff0c;输入地址、端口号就可以看到tomcat的欢…

ant 修改组件默认样式属性

得在 less 里面使用 :global 修改,不能是css文件. :global 修改是全局生效的,所以建议修改之前要加上calssName="样式名"; 不是 className={style.样式名} ,是直接写“”。 然后在调试工具找到你要修改的样式的属性名,如图: 来个单选框的样式修改代码,效果图:…

构建静态服务器_为静态网站构建无服务器联系表

构建静态服务器介绍 (Introduction) A few years ago AWS launched static hosting service S3, which was a paradigm shift for hosting static websites. The tech was crystal clear, all the static assets (HTML, CSS, and JS) would reside in an S3 bucket to host you…

Yii2之行为

Yii三大特性&#xff1a;属性、事件、行为。前面两篇文章已经分别讲解了属性和事件&#xff0c;本文接着讲讲yii的行为&#xff0c;分析yii行为的实现原理。 在yii中&#xff0c;一个对象绑定了行为之后&#xff0c;就拥有了所绑定行为拥有的所有事件&#xff0c;而且可以访问所…

ACM学习历程—HDU5586 Sum(动态规划)(BestCoder Round #64 (div.2) 1002)

题目链接&#xff1a;http://acm.hdu.edu.cn/showproblem.php?pid5586 题目大意就是把一段序列里面的数替换成f(x)&#xff0c;然后让总和最大。 首先可以计算出初始的总和&#xff0c;以及每一个值换成f(x)的增益a[x]。 那么就是求一段子序列a[x]的最值了&#xff0c;经典的D…

ant models 内获取 url 的参数传递到组件

models代码: import { getCList} from "@/services/api"; import { MessageTip } from @/utils/tools.js import { router } from umi;const customerModel = {namespace: customerModel,state: {channelList: [], // 渠道列表},reducers: {getUrlQuery(state, { …

软件开发向大数据开发过渡_如果您是过渡到数据科学的开发人员,那么这里是您的最佳资源...

软件开发向大数据开发过渡by Cecelia Shao邵Ce It seems like everyone wants to be a data scientist these days — from PhD students to data analysts to your old college roommate who keeps Linkedin messaging you to ‘grab coffee’.如今&#xff0c;似乎每个人都想…

php随笔(1)

PHP标记的四种风格 1、XML风格 <?php echo <p>Hello world</p> ; ?> 2、简短风格 <? echo <p>Hello world</p> ; ?> 3、SCRIPT <script language php>echo <p>Hello wordl.</p>;</script> 4、ASP风格 <% …

微信小程序云开发图片上传完整代码附效果图

在app.json里面加如下代码, 使用 WeUI组件库。点击跳转 "useExtendedLib": {"weui": true}, 先看效果图 wxml <!--pages/publish/publish.wxml--> <view class"page" data-weui-theme"{{theme}}"><view class"w…

图片lightbox2

1. 官网下载 http://lokeshdhakar.com/projects/lightbox2/ 2.引入 css jquery js 3. HTML格式 <a href"images/image-2.jpg" data-lightbox"roadtrip"> <img srcImage #1> </a> <a href"images/image-3.jpg" data-lig…

夏天和空调_您可以在今年夏天开始学习650项免费的在线编程和计算机科学课程...

夏天和空调Seven years ago, universities like MIT and Stanford first opened up free online courses to the public. Today, more than 900 schools around the world have created thousands of free online courses, popularly known as Massive Open Online Courses or …

bzoj1854: [Scoi2010]游戏

可以跑二分图 到第一个不能匹配的点就退出 嗯 还有并查集判环的做法&#xff1f; 1 #include<iostream>2 #include<algorithm>3 #include<cstdio>4 #include<cstdlib>5 #include<cstring>6 #include<string>7 8 using namespace std;9 10…

ant 获取当前url的参数

在util.js 中封装一个函数 公共函数&#xff1a; import { parse } from querystring; export const getPageQuery () > parse(window.location.href.split(?)[1]); 例如当前url 为&#xff1a;http://localhost:8000/manage/member_s_custome?corpIdww02c137b227b01c…

微软todo使用教程_Todo教程可能很有趣-但是,这是从头开始构建自己的项目的方法...

微软todo使用教程There are many great tutorials that walk you through creating apps, from simple todo lists to fully working web apps. But how do you start your own projects from scratch? Without the safety net of a tutorial, you might feel a bit lost on w…

python的with语句

from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker from setting import EREBUS_DB_CONNECT_STRING from contextlib import contextmanager# 创建数据库引擎&#xff0c;echo为True&#xff0c;会打印所有的sql语句 engine cre…

MSSQL 2012 拒绝了对对象 'extended_properties' (数据库 'mssqlsystemresource',架构 'sys')的 SELECT 权限...

查看数据库的表的时候报如下错误&#xff1a; MSSQL 2012 拒绝了对对象 extended_properties (数据库 mssqlsystemresource&#xff0c;架构 sys)的 SELECT 权限。 (Microsoft SQL Server&#xff0c;错误: 229) 解决方法&#xff1a; 在数据库里相应的用户权限中&#xff0c;把…

ant 接口返回文件流,前端自动下载实现

封装网络请求 : reqAxios.js import Axios from axios; import qs from qs; import { router } from umi; import { message } from antd;Axios.defaults.withCredentials = true// const httpUrl = https://xxx.cn/work_telecom_manage const httpUrl = window.location.o…

矩阵奇异值分解特征值分解_推荐系统中的奇异值分解与矩阵分解

矩阵奇异值分解特征值分解Recently, after watching the Recommender Systems class of Prof. Andrew Ng’s Machine Learning course, I found myself very discomforted not understanding how Matrix Factorization works.最近&#xff0c;在观看了Andrew Ng教授的机器学习课…

小程序云开发获取手机号完整代码 云函数中网络请求第三方接口

小程序云开发获取手机号完整代码 效果图&#xff1a; 小程序代码 <button open-type"getPhoneNumber" bindgetphonenumber"getPhoneNumber">登录</button> getPhoneNumber: function (e) {var that this;if (!e.detail.errMsg || e.detail.…

集合恒等式定律及文氏图

1、分配律 1.1 A∩(B∪C) (A∩B)∪(A∩C) 说明&#xff1a;从左至右&#xff0c;图1中三角形区域为 A&#xff0c;草绿色区域为 (B∪C)&#xff0c;即有三角形又有草绿色底色的区域即为 A∩(B∪C) 图2中三角形区域为 (A∩B)&#xff0c;草绿色区域为 (A∩C)&#xff0c;三角形…

微信 小程序布局 水平菜单

<!-- 菜单列表部分 --><view class"wear-menu"><view classmenu-box wx:key"menu" wx:for"{{menuList}}" wx:for-index"index"><view class"menu-img" bindtap"selectMenu" data-index"…

keras神经网络回归预测_如何使用Keras建立您的第一个神经网络来预测房价

keras神经网络回归预测by Joseph Lee Wei En通过李维恩 一步一步的完整的初学者指南&#xff0c;可使用像Deep Learning专业版这样的几行代码来构建您的第一个神经网络&#xff01; (A step-by-step complete beginner’s guide to building your first Neural Network in a c…