Codeforces Round #321 (Div. 2) A. Kefa and First Steps | 书脊
http://codeforces.com/contest/580/problem/A
分析: 这个…就扫一下, count一下每次有多少个连续的数是非递减的, 注意的是counter要从1开始. 因为如果一个数, 自己就是非递减的.
Read full article from Codeforces Round #321 (Div. 2) A. Kefa and First Steps | 书脊
http://codeforces.com/contest/580/problem/A
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 makes ai 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!
题目大意: 给一个数组, 找最大的连续非递减子数组.分析: 这个…就扫一下, count一下每次有多少个连续的数是非递减的, 注意的是counter要从1开始. 因为如果一个数, 自己就是非递减的.
3
4
5
6
7
8
9
10
11
12
13
14
|
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.readInt();
int max = 1;
int cur = 1;
int[] ary = IOUtils.readIntArray(in,n);
for (int i = 1; i < ary.length; i++) {
if (ary[i] >= ary[i-1])
cur++;
else
cur = 1;
max = Math.max(max, cur);
}
out.print(max);
}
|