题目链接: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();
}

最新文章

  1. Md5 签名算法
  2. Windows下安装node
  3. 宝洁的Pvp
  4. Appium技术点之解决屏幕无法点击的情况————Python版本
  5. C++写geohash
  6. 5 Logistic回归(二)
  7. IE 和 FF 写不同的CSS
  8. 记一次亲身踩过的hibernate的bug
  9. 一个用 js 实现点阵图的编辑器演示
  10. C++ this指针
  11. Linux正则表达式练习
  12. springMVC--XML解析
  13. C++程序设计方法3:虚函数
  14. 【剑指offer】链表第一个公共子结点
  15. CentOS 7.0关闭默认防火墙启用iptables防火墙
  16. linux 监控脚本运行时间
  17. PyCharm下载与激活
  18. 软件设计、DDD概念及落地时的一些零碎思考和记录2
  19. [转]使用 mitmproxy + python 做拦截代理
  20. Codeforces 834D - The Bakery(dp+线段树)

热门文章

  1. TeamView WaitforConnectFailed错误原因
  2. Server 2012 R2 Standard 安装运行PCS7时出现“无法启动此程序,因为计算机中丢失api-ms-win-crt-runtime-l1-1-0.dll”解决方法
  3. 转载 - Ubuntu源改国内源 与 批量更改ubuntu机器apt源
  4. Linux学习笔记 | 配置nginx
  5. iostat的输出
  6. kubernets之Deployment资源
  7. 私有镜像仓库Harbor基础介绍与部署
  8. 安装macosx10.13high serria
  9. 01-CentOS 8.1安装 Docker
  10. Linux TCP漏洞 CVE-2019-11477 CentOS7 修复方法