Giant Sequoia

  • 题目
  • 翻译(机翻)
  • 思路
  • 代码

UTPC Contest 02-25-22 Div. 2 (Beginner) F: 题目链接.

题目

Alfred, an avid botanist and lumberjack, while traveling across the state of California, has come across an absolutely humongous giant sequoia tree. Being the botanist that he is, Alfred would like to examine this fascinating giant sequoia tree in great depth. More specifically, he would like to observe its branches.
Each of the n branches of the giant sequoia tree has a specific length associated with it, and certain branches are longer than others. Because of this, Alfred was inspired to solve a certain problem, though his skills in computing are quite limited, and he has come to you for help!
Alfred would like to figure out the longest strictly-increasing consecutive sub-array (a sub-array such that ai+1>ai for each i except the last in the sub-array) of the giant sequoia tree branches. However, he is torn between his love for botany and his duties as a lumberjack. He can either choose to leave the tree alone and compute the answer directly, or he can chop off a consecutive sub-array of size exactly k from the giant sequoia tree before running his computations. More formally, Alfred can choose some index i such that i+k−1≤n and then remove the branches at indices i,i+1,i+2,…,i+k−1. Since he doesn’t have all that much energy after hiking all day, he can only perform this action a maximum of one time.
Given his choices, can you help Alfred find the longest strictly-increasing consecutive sub-array within the giant sequoia tree after at most one chop of size k ?

翻译(机翻)

Alfred,一个狂热的植物学家和伐木工人,在穿越加利福尼亚的时候,遇到了一棵绝对巨大的巨型红杉树。作为一个植物学家,阿尔弗雷德想深入研究这棵迷人的巨杉树。更具体地说,他想观察它的树枝。
巨型红豆杉树的每一个分支都有一个特定的长度,某些分支比其他分支长。正因为如此,阿尔弗雷德受到启发,想解决某个问题,尽管他在计算方面的技能相当有限,他已经向你寻求帮助了
Alfred想算出巨型红杉树树枝中最长的严格递增的子数(一个子数,使ai+1>ai的每个i,除了子数的最后一个)。然而,他在对植物学的热爱和作为一个伐木工人的职责之间纠结。他可以选择不理会这棵树,直接计算出答案,或者他可以在运行计算之前,从巨杉树上砍下一个大小正好为k的连续子数组。更正式地说,Alfred可以选择某个索引i,使i+k-1≤n,然后删除索引i,i+1,i+2,…,i+k-1处的分支。由于他爬了一天的山,没有那么多的精力,他最多只能做一次这个动作。
鉴于他的选择,你能帮助Alfred在最多一次k大小的砍伐后,找到巨杉树内最长的严格递增的连续序列吗?

思路

用一个数组来标记一下上升序列的起点,如 序列 [1,2,3,2,5] ,其对应的起点数组为: [0,0,0,3,3],在预处理时,先统计不砍的长度,后面在分成两段统计上升长度

代码

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int dp[maxn], a[maxn];
int main()
{ios::sync_with_stdio(false);cin.tie(0);int n, k;cin >> n >> k;for (int i = 1; i <= n; ++i){cin >> a[i];}dp[1] = 1;int ans = 1;// 预处理起点,以及不砍的最大长度for (int i = 2; i <= n; ++i){if (a[i] >= a[i - 1]){dp[i] = dp[i - 1];}else{dp[i] = i;}if (i - dp[i] + 1 > ans){ans = i - dp[i] + 1;}}// 循环砍的结果for (int i = 2; i <= n - k + 1; i++){// 砍部分的左边最大小于砍部分的右边最小,构成上升if (a[i + k] > a[i - 1]){int right = i + k;int left = i - 1;int count = 0;// 统计长度for (int i = right; i <= n; i++){if (dp[i] != dp[right]){break;}count++;}for (int i = left; i >= 1; i--){if (dp[i] != dp[left]){break;}count++;}ans = max(ans, count);}}cout << ans << endl;// return 0;
}

Giant Sequoia(UTPC Contest 02-25-22 Div. 2 (Beginner))相关推荐

  1. Codeforces Beta Round #22 (Div. 2 Only) E. Scheme(DFS+强连通)

    题目大意 给了 n(2<=n<=105) 个点,从每个点 u 出发连向了一个点 v(共 n 条边) 现在要求添加最少的边使得整个图是一个强连通图 做法分析 这道题千万不要一般化:先求强连通 ...

  2. Unparseable date: “Fri Sep 02 21:22:57 CST 2022

    异常 Unparseable date: "Fri Sep 02 21:22:57 CST 2022"(不可分解的日期:XXX) Exception in thread " ...

  3. contest: UTPC Contest 10-28-22 Div. 1 (Advanced), problem: (C)

    #include <stdio.h> int main() {int k,p;scanf("%d %d",&k,&p);int i=0;int m[10 ...

  4. 25条div+CSS编程提醒及小技巧整理

    1.ul标签在Mozilla中默认是有padding值的,而在IE中只有margin有值. 2.同一个的class选择符可以在一个文档中重复出现,而id选择符却只能出现一次:对一个标签同时使用clas ...

  5. CodeForces Contest #1114: Round #538 (Div. 2)

    比赛传送门:CF #1114. 比赛记录:点我. 又 FST 了. [A]Got Any Grapes? 题意简述: 有三个人,第一个人需要吃绿色葡萄至少 \(a\) 个,第二个人需要吃绿色和紫色葡萄 ...

  6. jzoj 1388. 【2012.02.25普及组】探索的奶牛

    题目描述 FJ的奶牛喜欢探索农场周围的地形.一开始,所有N(1<=N<=1,000,000,000)只奶牛一起出发,但当碰到路口时,这一群牛可能会分成两部分(不能为空),每一部分都继续前进 ...

  7. 前端基础学习笔记(一)2018.02.26-03.22

    HTML <!DOCTYPE> 告知浏览器的解析器用什么标准解析这个文档, 不存在或者格式不正确会导致文档以 兼容模式 呈现. HTML5 只需要写<!DOCTYPE HTML> ...

  8. 本周ASP.NET英文技术文章推荐[02/25 - 03/03]

    摘要 本期共有9篇文章: 借助UpdatePanel实现延迟加载 技巧和诀窍:ASP.NET中的URL重写 Sys.WebForms.PageRequestManagerParserErrorExce ...

  9. 实习工作日志-2019.02.25

    任务: 升级部署在一台浪潮服务器.一台M3C服务器上的VMware, 从5.1到5.5 方便内外网版本对接. 遇到的问题: 在老毛桃镜像安装系统上 VMware的ios镜像不识别 只能识别window ...

最新文章

  1. 基于VLC的播放器开发
  2. Platforms/iPhoneSimulator.platform/Developer/usr/bin/g++-4.2 failed with exit code 1问题总结及解决方案...
  3. 作用域,上下文,闭包
  4. luogu P1231 教辅的组成
  5. ArrayList集合的使用和源码详细分析
  6. 简书 php三级联动,JS 实现三级联动
  7. 割线法求解过程_求解稀疏优化问题2——临近点方法+半光滑牛顿法
  8. 什么是堆栈的构造方法?向上生长堆栈,向下生长堆栈
  9. for循环中gets_Python中for循环的一些非常规操作
  10. android computescroll_Android Scroller与computeScroll的调用机制关系
  11. SELinux系列(十三)—默认安全上下文的查询和修改(semanage命令)
  12. 情人节,我用字符画出了一个对象!
  13. html5趣味智力答题测试,10个趣味智力题及答案
  14. VS2010中文版微软官方下载
  15. jeffery0207博客导航
  16. 张桂梅PK清华副教授:不要站在高楼上,傲慢地指着大山
  17. 网易2019实习生招聘笔试-牛牛的闹钟
  18. SIM卡APN选择说明
  19. 极客时间 - Vim学习
  20. 靶机渗透练习35-ContainMe

热门文章

  1. MYSQL配置初始化
  2. ADS1258---FPGA驱动(一)
  3. 森浦资讯是一家怎么样的公司
  4. maven命令的方式
  5. java二维码生成 使用SSM框架 搭建属于自己的APP二维码合成、解析、下载
  6. 如何完全清除linux内核,清除旧的Linux内核
  7. 数字图像处理之图像锐化算法
  8. js和jquery实现页面跳转的几种方式
  9. Matlab求出图像中每个细胞的细胞核与核仁面积之比代码
  10. 1N5408-ASEMI整流二极管1N5408