• 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<kn1≤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≤pin1≤pi≤n ; pipjpi≠pj if iji≠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;
    }
  • 相关阅读:
    牛客-小V和gcd树
    CF-Codeforces Round #639 (Div. 2)-D-Monopole Magnets
    牛客-牛牛染颜色
    CF-637
    提高办公效率——快捷键
    FusionComputer虚拟机克隆后出现网卡服务重启失败解决办法
    centos7.5mini中Firewalld端口不通解决办法及想法
    FusionConputer热迁移过程记录
    Java集合框架之Iterable接口
    初识Java集合框架
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/13297113.html
Copyright © 2020-2023  润新知