一、题目链接
二、题目分析
(一)算法标签
枚举
(二)解题思路
三、AC代码
解法一:
#include <iostream>
using namespace std;
const int N = 10000;
int n;
int a[N];
int main()
{
cin >> n;
for (int i = 1; i <= n; i ++ )
{
scanf("%d", &a[i]);
}
int cnt = 0;
for (int i = 1; i <= n; i ++ )
{
int max_v = 0, min_v = 10010;
for (int j = i; j <= n; j ++ )
{
max_v = max(a[j], max_v);
min_v = min(a[j], min_v);
if (j - i == max_v - min_v)
cnt ++ ;
}
}
cout << cnt << endl;
return 0;
}