https://acm.zcmu.edu.cn/JudgeOnline/problem.php?id=2232https://acm.zcmu.edu.cn/JudgeOnline/problem.php?id=2232一开始觉得题目有点看不明白,但仔细思考一下,如果一个数组最大值与最小值相等的话,那么是不是只可能是它本身或者若干个它组成的数组。
#include<bits/stdc++.h>
using namespace std;
long long Mypermutation(long long x)
{
if (x == 0||x==1)
return 1;
else
return x + Mypermutation(x-1);
}
int main()
{
long long x, y, n, sum = 0, cot = 1;
cin >> n >> x;
y = x;
for (int i = 1; i < n; i++)
{
cin >> x;
if (x == y)
{
cot++;
continue;
}
else
{
y = x;
sum += Mypermutation(cot);
cot = 1;
}
}
sum += Mypermutation(cot);//一开始还有一次没算
cout << sum << endl;
return 0;
}