zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    Guava入门第四章(Objects)
    Guava入门第三章(Preconditions)
    Guava入门第二章(Splitter)
    Guava入门第一章(Joiner)
    Docker入门第六章
    Docker遇到的问题
    Docker命令图
    2016-08-26-Java比较器的使用
    2017-10-6-MyBatis配置简述
    2017-9-17-Java Exception小结
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/13297113.html
Copyright © 2011-2022 走看看