Educational Codeforces Round 60 (Rated for Div. 2) ----A - Best Subsegment(思维题)
程序员文章站
2022-07-15 12:47:27
...
链接:http://codeforces.com/problemset/problem/1117/A
来源:Codeforces
想到了思路,却败给了实现方法。此题大意就是,我们找到一个利用上述公式可以计算出一个值,我们需要一个找到最大的值,输出构成这个值的区间的最大长度.我们当长度为1的时候,一个值就是最大的,如果在增加一个数这个值只会不变或者变小,所以我们只需要找到这个数组中最大的数连续出现了几次。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
//typedef long long LL;
const int Max_n=100005;
int a[Max_n];
int main(){
int n;
scanf("%d",&n);
int mmax=0;
for (int i=0;i<n;++i){
scanf("%d",&a[i]);
if(a[i]>mmax) mmax=a[i];
}
int cnt=0,res=0;
for(int i=0;i<n;++i){
if(a[i]==mmax){
cnt++;
if(res<cnt) res=cnt;
}
else cnt=0;
}
printf("%d\n",res);
return 0;
}
上一篇: Java高精度类型
推荐阅读
-
Educational Codeforces Round 60 (Rated for Div. 2) ----A - Best Subsegment(思维题)
-
Codeforces Educational Codeforces Round 80 (Rated for Div. 2) E - Messenger Simulator(树状数组+思维)
-
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms(思维)
-
Educational Codeforces Round 50 (Rated for Div. 2) D. Vasya and Arrays(前缀和,思维)
-
E. Vasya and a Tree (前缀和思维) Educational Codeforces Round 54 (Rated for Div. 2)
-
Educational Codeforces Round 48 (Rated for Div. 2) D. Vasya And The Matrix(思维/构造)
-
Educational Codeforces Round 52 (Rated for Div. 2)B. Vasya and Isolated Vertices·「模拟,思维」