Codeforces 580A
来源:互联网 发布:全国各地一手车主数据 编辑:程序博客网 时间:2024/06/06 04:27
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1 ≤ i ≤ n) he makesai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.
Help Kefa cope with this task!
The first line contains integer n (1 ≤ n ≤ 105).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print a single integer — the length of the maximum non-decreasing subsegment of sequence a.
62 2 1 3 4 1
3
32 2 9
3
In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
解题:此题是求最长的非递减子数列,遍历时不断记录与上一个值进行比较,最后得到最大值
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cmath>
using namespace std;
int a[100010];
int b[10001];
int main()
{
int n;
while(cin>>n){
int t=1,l=1;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=1;i<n;i++){
if(a[i]>=a[i-1]){
l++;
}
else l=1;
if(l>t) t=l;
}
cout<<t<<endl;
}
return 0;
}
- Codeforces 580A
- CodeForces-a
- Codeforces 903A A
- CodeForces 580A Kefa and First Steps
- Codeforces 580A Kefa and First Steps
- Codeforces-580A-Kefa and First Steps
- CodeForces 580A Kefa and First Steps
- codeforces 580A Kefa and First Steps
- codeforces 580A Kefa and First Steps
- CodeForces 18A A - Triangle
- CodeForces 133A A. HQ9+
- codeforces 651A A. Joysticks
- 【Codeforces 597A】A. Divisibility
- 【 Codeforces 615A】A. Bulbs
- A. Divisibility CodeForces 597A
- codeforces 417A A. Elimination
- CodeForces 534A A. Exam
- codeforces#98 a
- 回归-简述
- Listener监听器
- 人生感悟随笔
- resful API
- 数据库语言(DDL和DML)
- Codeforces 580A
- 使用iObjects java进行多进程生成缓存
- UI 自动化高亮元素与截图小工具
- 关于servlet的@WebServlet注解。
- 11
- Git 提交项目代码
- 如何用anaconda安装cv2(python—opencv)
- 10分钟了解产品运营到底是什么
- 12