580A

来源:互联网 发布:手机sdr软件 编辑:程序博客网 时间:2024/06/16 17:13

题目大意:

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

题目分析:

   我的思路是在开一个数组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);    }}


0 0
原创粉丝点击