Educational Codeforces Round 91 (Rated for Div. 2) A. Three Indices(暴力)
You are given a permutation p1,p2,…,pnp1,p2,…,pn . Recall that sequence of nn integers is called a permutation if it contains all integers from 11 to nn exactly once.
Find three indices ii , jj and kk such that:
- 1≤i<j<k≤n1≤i<j<k≤n ;
- pi<pjpi<pj and pj>pkpj>pk .
Or say that there are no such indices.
Input
The first line contains a single integer TT (1≤T≤2001≤T≤200 ) — the number of test cases.
Next 2T2T lines contain test cases — two lines per test case. The first line of each test case contains the single integer nn (3≤n≤10003≤n≤1000 ) — the length of the permutation pp .
The second line contains nn integers p1,p2,…,pnp1,p2,…,pn (1≤pi≤n1≤pi≤n ; pi≠pjpi≠pj if i≠ji≠j ) — the permutation pp .
Output
For each test case:
- if there are such indices ii , jj and kk , print YES (case insensitive) and the indices themselves;
- if there are no such indices, print NO (case insensitive).
If there are multiple valid triples of indices, print any of them.
Example
Input
Copy
3
4
2 1 4 3
6
4 6 1 2 5 3
5
5 3 1 2 4
Output
Copy
YES
2 3 4
YES
3 5 6
NO
就…硬暴力。(不过显然可以优化到O(n)QAQ
#include <bits/stdc++.h> using namespace std; int n, a[1005]; int main() { int t; cin >> t; while(t--){ cin >> n; int x = 0, y = 0, z = 0; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 2; i <= n - 1; i++){ for(int j = 1; j < i; j++){ if(a[j] < a[i]){ x = j; break; } } for(int j = i + 1; j <= n; j++){ if(a[j] < a[i]){ y = j; break; } } if(x && y){ z = i; break; }else{ x = y = z = 0; } } if(z){ cout << "YES" << endl; cout << x << ' ' << z << ' ' << y << endl; }else{ cout << "NO" <<endl; } } //system("pause"); return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!