580A
2015-09-27 10:18
246 查看
题目大意:
给一段数组序列,求最长的非降序列;
题目分析:
我的思路是在开一个数组s,保存当前非降序列的个数,如果s[i] >= s[i-1]; s[i] = s[i-1]+1; 反之 s[i] = 1;
不过这个数组是可以不用的;
题目地址:点击打开链接
参考代码:
给一段数组序列,求最长的非降序列;
题目分析:
我的思路是在开一个数组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); } }
相关文章推荐
- stl string常用函数
- webvtt字幕转srt字幕方法
- Android 开发中的日常积累
- 在机器学习中用到了各式各样的距离
- Printk打印优先级设定
- 宁波金鸟服饰有限公司举行公司化运作第二阶段总结表彰大会
- OBPS开发平台——导入功能vb代码解析
- Seoul 2007 Meteor 流星 ,LA 3905
- 数据库相同版本的数据文件导入时出错
- 实现多个整数相加。
- C++静态库与动态库
- HDU 5482(思路题目)
- 有序的整数划分,青蛙跳台阶问题 MATLAB
- 韩顺平 java 第21讲、第22讲、第23讲、第24讲 集合
- javascript 比量str今天的日期是,参数diff
- App.Config详解
- mysql子查询慢的问题
- 如何创建 C# 控制台应用程序
- spark集群搭建
- 5477 A Sweet Journey (贪心_上海网络赛)