码迷,mamicode.com
首页 > 其他好文 > 详细

VJ A - Three Indices 7.26

时间:2020-07-26 23:23:20      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:序列   没有   speed   ace   标记   nbsp   with   syn   while   

#include<bits/stdc++.h>
#define ll long long
#define speed_up ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const ll nl=1e5+5;
/*
有一串数包含了1~n,(是前n个自然数打乱的组合),从中找出三个数i,j,k使j大于i和k,且它们的下标要从小到大,输出这三个数的下标
用一个初始化为0的数组标记(只要这个数比前面的数小就标记为1)
而未标记的数(除了第一个数)一定也大于它前面的那个数,否则会被标记为1
这样数组b只要存在序列01就表示一定存在题目让找的i,j,k(0对应j,1对应k)
只要输出最先出现的这三个数就可以
2 1 4 3
0 1 0 1
4 6 1 2 5 3
0 0 1 0 0 1
5 3 1 2 4
0 1 1 0 0
从第二位开始没有序列01
*/
int main()
{
    speed_up;
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n],b[n]={0};
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            if(i>0&&a[i-1]>a[i])
            {
                b[i]=1;
            }
        }
        int s=0;
        for(int i=2;i<n;i++)
        {
            if(b[i-1]==0&&b[i]==1)
            {
                cout<<"YES"<<endl;
                cout<<i-1<<" "<<i<<" "<<i+1<<" "<<endl;
                s=1;
                break;
            }
        }
        if(s==0)
        {
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

VJ A - Three Indices 7.26

标签:序列   没有   speed   ace   标记   nbsp   with   syn   while   

原文地址:https://www.cnblogs.com/SyrupWRLD999/p/13381702.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!