qq_23270265 于 2014.11.27 20:16 提问
- acm题,测试很多数据都没错,一提交就WA 1C
-
/*
Judge InfoMemory Limit: 32768KB Case Time Limit: 1000MS Time Limit: 1000MS Judger: Number Only Judger
Description
We are given a integer sequence, your job is find the length of the longest contiguous subsequence that is strictly increasing or strictly decreasing.
InputFirst number T (1<=T<=100), represent how many test cases. For each test case the first number is N (1=< N <= 50). Then N, positive integers are followed, all of them are less than 101.
Output
For each test case output the answer in one line.
Sample Input3
3 1 1 1
3 1 2 3
4 4 3 2 1Sample Output
1
3
4*/
#include
int main()
{
int b[10000];
int max;
int sheng,jiang;//记录升序和降序的长度
int T;
int N;
int i;
scanf("%d",&T);
while(T--)
{
sheng=1;jiang=1;max=1;scanf("%d",&N); for(i=0;i<N;i++) scanf("%d",&b[i]); for(i=0;i<N-1;i++) { if(b[i]<b[i+1]) { sheng++; if(sheng>max) max=sheng; jiang=1; } else if(b[i]>b[i+1]) { jiang++; if(jiang>max) max=jiang; sheng=1; } } printf("%d\n",max); } return 0;
}
-
- oqqTim12 2014.12.08 19:43
算法错了。DP入门题目。请百度动态规划,参考:
http://blog.csdn.net/non_cease/article/details/7307835
-
-
lm_whales
2015.09.23 10:40
没能处理好 strictly increasing or strictly decreasing 中的 strictly
二者相等,应该也是 初始化为1
-
- fmoalm 2015.11.30 15:12
路过水一贴,O(∩_∩)O。
-
- qq_38306502 2017.11.29 14:47
strictly初始化为1
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!