题目链接:https://codeforces.com/contest/1385/problem/C

题意

去除一个数组的最短前缀使得余下的数组每次从首或尾部取元素可以排为非减序。

题解一

当两个大数夹着一个小数那么第一个大数及其之前的数必须要去掉,比如 $1,1,2,1,2$,要去除的前缀长为 $3$,但是考虑到也会有 $1,1,2,1,1,2$ 的情况,所以可以将原数组去重后判断每三个相邻的元素。

代码

#include <bits/stdc++.h>
using namespace std; void solve() {
int n; cin >> n;
int a[n] = {}; for (int i = 0; i < n; ++i) cin >> a[i];
vector<pair<int, int>> v;
for (int i = 0; i < n; ) {
int j = i + 1;
while (j < n and a[j] == a[i]) ++j;
v.emplace_back(a[i], j - 1);
i = j;
}
for (int i = v.size() - 1; i - 2 >= 0; --i) {
if (v[i - 2].first > v[i - 1].first and v[i - 1].first < v[i].first) {
cout << v[i - 2].second + 1 << "\n";
return;
}
}
cout << 0 << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}

题解二

换言之,即找右端山脚为数组末尾元素的最长的山峰。

代码

#include <bits/stdc++.h>
using namespace std; void solve() {
int n; cin >> n;
int a[n] = {}; for (auto &i : a) cin >> i;
int p = n - 1;
while (p - 1 >= 0 and a[p - 1] >= a[p]) --p;
while (p - 1 >= 0 and a[p - 1] <= a[p]) --p;
cout << p << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}

Codeforces Round #656 (Div. 3) C. Make It Good的更多相关文章

  1. Codeforces Round #656 (Div. 3) D. a-Good String

    题目链接:https://codeforces.com/contest/1385/problem/D 题意 一个小写字母串称为 $c-good\ string$,如果至少满足以下条件之一: 字符串长度 ...

  2. Codeforces Round #656 (Div. 3) B. Restore the Permutation by Merger

    题目链接:https://codeforces.com/contest/1385/problem/B 题意 有两个大小为 $n$ 的相同的排列,每次从二者或二者之一的首部取元素排入新的数组,给出这个大 ...

  3. Codeforces Round #656 (Div. 3) A. Three Pairwise Maximums

    题目链接:https://codeforces.com/contest/1385/problem/A 题意 给出三个正整数 $x,y,z$,找出三个正整数 $a,b,c$ 使得 $x = max(a, ...

  4. Codeforces Round #656 (Div. 3) 题解

    A. Three Pairwise Maximums #构造 题目链接 题意 给定三个正整数\(x,y,z\),要求找出正整数\(a,b,c\),满足\(x=max(a,b), y=max(a,c), ...

  5. Codeforces Round #656 (Div. 3) D. a-Good String (DFS)

    题意:有一个长度为\(n=2^k\)的字符串,对于某个字符\(c\),我们定义他是一个\(c-good\),如果: ​ 1.\(len=1\),并且\(s[1]=c\). ​ 2.\(len>1 ...

  6. Codeforces Round #656 (Div. 3) C. Make It Good (贪心,模拟)

    题意:给你一个数组\(a\),可以删除其前缀,要求操作后得到的数组是"good"的.对于"good":可以从数组的头和尾选择元素移动到新数组,使得所有元素移动后 ...

  7. Codeforces Round #656 (Div. 3) B. Restore the Permutation by Merger (模拟)

    题意:有两个完全相同的排列,将其中一个的元素按相对顺序插入另外一个排列中,给你操作完的排列,求原排列. 题解:感觉看看样例就能直接写了啊,直接遍历,用桶存数字个数,如果桶为空,直接输出即可. 代码: ...

  8. Codeforces Round #656 (Div. 3) A. Three Pairwise Maximums (数学)

    题意:给你三个正整数\(x\),\(y\),\(z\),问能够找到三个正整数\(a\),\(b\),\(c\),使得\(x=max(a,b)\),\(y=max(a,c)\),\(z=max(b,c) ...

  9. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. 9. 细节见真章,Formatter注册中心的设计很讨巧

    目录 本文提纲 版本约定 你好,我是A哥(YourBatman). Spring设计了org.springframework.format.Formatter格式化器接口抽象,对格式化器进行了大一统, ...

  2. 基于 OpenMP 的奇偶排序算法的实现

    代码: #include <omp.h> #include <iostream> #include <cstdlib> #include <ctime> ...

  3. python模块详解 | progressbar

    参考官方文档:https://pypi.org/project/progressbar/#description progressbar 安装: pip install progressbar pro ...

  4. Log4j配置按照文件大小和日期分割日志文件

    目录 Log4j 下载地址 文件大小分割日志文件 以日期分割每天产生一个日志文件 自定义信息输出到日志文件 Log4j 下载地址 Log4j是Apache的一个开源项目,通过使用Log4j,我们可以控 ...

  5. 怎么判断innodb 日志缓冲区该设置为多大呢

    怎么判断innodb 日志缓冲区该设置为多大呢

  6. Nacos使用和注册部分源码介绍

    Nacos简单介绍 Nacos致力于帮助您发现.配置和管理微服务.Nacos提供了一组简单易用的特性集,帮助您快速实现动态服务发现.服务配置.服务元数据及流量管理.Nacos帮助您更敏捷和容易地构建. ...

  7. 使用CDN访问免备案网站

    如何使用CDN绕过服务器域名备案 前言 不得不说,大陆需要备案,时间真的有点长,至少得5天~20天起步,对于我们这些火急火燎的站长还是比较难受的.这里教大家如何使用cdn绕过备案, 访问速度很快,亲测 ...

  8. Navicat linux 官方最新版安装破解

    我们直接去官网下载linux版navicat 下载好之后执行命令打开软件 chmod +x navicat15-premium-cs.AppImage ./navicat15-premium-cs.A ...

  9. mysqlG基于TID模式同步报错 (Last_IO_Errno: 1236)

    mysqlG基于TID模式同步报错Last_IO_Errno: 1236 Last_IO_Error: Got fatal error 1236 from master when reading da ...

  10. Linux的环境变量配置在/etc/profile或/etc/profile.d/*.sh文件中的区别是什么?

    @ 目录 login shell non-login shell 它们的区别 Linux的环境变量可在多个文件中配置,如/etc/profile,/etc/profile.d/*.sh,~/.bash ...