Educational Codeforces Round 91 (Rated for Div. 2) A. Three Indices
2024-10-19 04:04:53
题目链接:https://codeforces.com/contest/1380/problem/A
题意
给出一个大小为 $n$ 的排列,找出是否有三个元素满足 $p_i < p_j\ and\ p_j > p_k$ 。
题解
如果排列为增序或降序则无解,否则一定存在三个相邻的元素满足 $p_i < p_{i+1}\ and\ p_{i+1} > p_{i+2}$ 。
证明
若不存在,则 $p_i \ge p_{i+1}\ or\ p_{i+1} \le p_{i+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];
for (int i = 1; i + 1 < n; i++) {
if (a[i - 1] < a[i] and a[i] > a[i + 1]) {
cout << "YES" << "\n";
cout << i << ' ' << i + 1 << ' ' << i + 2 << "\n";
return;
}
}
cout << "NO" << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}
最新文章
- Md5 签名算法
- Windows下安装node
- 宝洁的Pvp
- Appium技术点之解决屏幕无法点击的情况————Python版本
- C++写geohash
- 5 Logistic回归(二)
- IE 和 FF 写不同的CSS
- 记一次亲身踩过的hibernate的bug
- 一个用 js 实现点阵图的编辑器演示
- C++ this指针
- Linux正则表达式练习
- springMVC--XML解析
- C++程序设计方法3:虚函数
- 【剑指offer】链表第一个公共子结点
- CentOS 7.0关闭默认防火墙启用iptables防火墙
- linux 监控脚本运行时间
- PyCharm下载与激活
- 软件设计、DDD概念及落地时的一些零碎思考和记录2
- [转]使用 mitmproxy + python 做拦截代理
- Codeforces 834D - The Bakery(dp+线段树)
热门文章
- TeamView WaitforConnectFailed错误原因
- Server 2012 R2 Standard 安装运行PCS7时出现“无法启动此程序,因为计算机中丢失api-ms-win-crt-runtime-l1-1-0.dll”解决方法
- 转载 - Ubuntu源改国内源 与 批量更改ubuntu机器apt源
- Linux学习笔记 | 配置nginx
- iostat的输出
- kubernets之Deployment资源
- 私有镜像仓库Harbor基础介绍与部署
- 安装macosx10.13high serria
- 01-CentOS 8.1安装 Docker
- Linux TCP漏洞 CVE-2019-11477 CentOS7 修复方法