tian花板 2014-11-27 12:16 采纳率: 0%
浏览 2000
已结题

acm题,测试很多数据都没错,一提交就WA

/*
Judge Info

Memory 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.
Input

First 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 Input

3
3 1 1 1
3 1 2 3
4 4 3 2 1

Sample 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;

}

  • 写回答

4条回答 默认 最新

  • _-_小T 2014-12-08 11:43
    关注

    算法错了。DP入门题目。请百度动态规划,参考:
    http://blog.csdn.net/non_cease/article/details/7307835

    评论

报告相同问题?

悬赏问题

  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题