AcWing 1210. 连号区间数
原题链接
简单
作者:
hegehog
,
2020-07-08 21:06:32
,
所有人可见
,
阅读 581
C++代码
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 10005;
const int INF = 1e8;
int a[N];
int n;
//暴力枚举(不重不漏):
int main()
{
cin >> n;
for(int i = 1; i <= n; i ++ )
cin >> a[i];
int res = 0;
for(int i = 1; i <= n; i ++)
{
int maxn = a[i], minn = a[i];
for(int j = i; j <= n; j ++)
{
if( a[j] > maxn) maxn = a[j];
if( a[j] < minn) minn = a[j];
if( maxn - minn == j - i) res++;
}
}
cout << res << endl;
return 0;
}