https://ac.nowcoder.com/acm/contest/318/B

题解:签到题啊,没什么好说的,直接O(n^2)暴力莽就行了。先枚举区间的左端点,然后遍历后面的数据,同时记录一个最大值,如果当前这个数比前面记录的最大值要大则更新答案;若出现小于左端点的数则break。就没了。

C++版本一

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=1000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
int a[N];
int b[N];
int c[N];
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    while(~scanf("%d",&t)){
        while(t--){
            scanf("%d",&n);
            int ans=0;
            for(int i=1;i<=n;i++){
                scanf("%d",&a[i]);
            }
            for(int i=1;i<=n;i++){
                int maxl=a[i];
                int y=0;
                for(int j=i+1;j<=n;j++){
                    if(a[i]<a[j]){
                        if(a[j]>maxl){
                            maxl=a[j];
                            y=j;
                        }
                    }else{
                        break;
                    }
                }
                ans=max(ans,y-i);
            }
            printf("%d\n",ans);

        }
    }


    //cout << "Hello world!" << endl;
    return 0;
}

C++版本二

#include <bits/stdc++.h>
using namespace std;
int n, ans, ar[1005];
int main(int argc, char const *argv[]){
    int tim;
    scanf("%d", &tim);
    while(tim --) {
        scanf("%d", &n);
        for(int i = 0; i < n; ++i) {
            scanf("%d", &ar[i]);
        }
        ans = 0;
        for(int i = 0, j, mmax; i < n - 1; ++i) {
			mmax = ar[i];
			for(j = i + 1; j < n; ++j) {
				if(ar[j] > mmax) ans = max(ans, j - i);
				mmax = max(mmax, ar[j]);
				if(ar[j] < ar[i]) break;
			}
        }
        printf("%d\n", ans);
    }
    return 0;
}