题目链接: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. Centos镜像国内最全下载地址

    CentOS 官方下载地址:https://www.centos.org/download/Centos国内下载源http://man.linuxde.net/download/CentOShttp: ...

  2. JVM故障处理工具,使用总结

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 用都用不到怎么学? 没有场景.没有诉求,怎么学习这些似乎用不上知识点. 其实最好的方 ...

  3. Flutter 基础组件:文本、字体样式

    // 文本.字体样式 import 'package:flutter/material.dart'; class TextFontStyle extends StatelessWidget { // ...

  4. 使用OpenCV进行简单的人像分割与合成

    图像合成 实现思路 通过背景建模的方法,对源图像中的动态人物前景进行分割,再将目标图像作为背景,进行合成操作,获得一个可用的合成影像. 实现步骤如下. 使用BackgroundSubtractorMO ...

  5. 【Oracle】迁移表到其他的表空间

    有些时候需要将表迁移到其他的表空间,在将表空间做相关的操作 下面是命令如何迁移表空间 SQL> alter table 表名 move tablespace 表空间名; 如果有很多的表想要迁移的 ...

  6. Netty的简单Demo

    这个demo是通过网上下载: 使用maven构建的: 项目结构: pom.xml: <dependencies> <dependency> <groupId>io. ...

  7. 核酸检测:让我明白AQS原理

    春节越来越近了,疫情也越来越严重,但挡不住叫练携一家老小回老家(湖北)团聚的冲动.响应国家要求去我们做核酸检测了. 独占锁 早上叫练带着一家三口来到了南京市第一医院做核酸检测,护士小姐姐站在医院门口拦 ...

  8. pycharm2021永久激活

    Pycharm破解版地址: 链接: https://pan.baidu.com/s/1dEkzKRFMaeNjWF4h7y2TdQ 提取码: eqr3  Anaconda地址:版本是python3.6 ...

  9. libuv中实现tcp服务器

    目录 1.说明 2.libuv的tcp server 3.API简介 3.1.uv_tcp_init 3.2.uv_ip4_addr 3.3.uv_tcp_bind 3.4.uv_listen 3.5 ...

  10. git的使用学习笔记--项目版本操作

    一.使用场景 版本回退:上线失败--需要回退到上个版本 二.操作 先编辑  vim text.txt git status git add .       这个命令能看到所有的增加操作 git com ...