您的位置:首页 > 其它

580A

2015-09-27 10:18 246 查看
题目大意:

给一段数组序列,求最长的非降序列;

题目分析:

我的思路是在开一个数组s,保存当前非降序列的个数,如果s[i] >= s[i-1]; s[i] = s[i-1]+1; 反之 s[i] = 1;

不过这个数组是可以不用的;

题目地址:点击打开链接

参考代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int n, a[100000+10];

int main()
{
while(scanf("%d", &n) != EOF){
for(int i = 0; i < n; ++i)
scanf("%d", &a[i]);
int _max = -1;
int k = 1;
for(int i = 1; i < n; ++i){
if(a[i] >= a[i-1]) k++;
else k = 1;
if(k > _max)
_max = k;
}
_max = max(_max, k);
printf("%d\n", _max);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: