Deque (问题)

Deque

Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 9   Accepted Submission(s) : 0
Problem Description
Today, the teacher gave Alice extra homework for the girl weren't attentive in his class. It's hard, and Alice is going to turn to you for help.
The teacher gave Alice a sequence of number(named A) and a deque. The sequence exactly contains N integers. A deque is such a queue, that one is able to push or pop the element at its front end or rear end. Alice was asked to take out the elements from the sequence in order(from A_1 to A_N), and decide to push it to the front or rear of the deque, or drop it directly. At any moment, Alice is allowed to pop the elements on the both ends of the deque. The only limit is, that the elements in the deque should be non-decreasing.
Alice's task is to find a way to push as many elements as possible into the deque. You, the greatest programmer, are required to reclaim the little girl from despair.
 

Input
The first line is an integer T(1≤T≤10) indicating the number of test cases.
For each case, the first line is the length of sequence N(1≤N≤100000).
The following line contains N integers A 1,A 2,…,A N.
 

Output
For each test case, output one integer indicating the maximum length of the deque.
 

Sample Input
  
  
3 7 1 2 3 4 5 6 7 5 4 3 2 1 5 5 5 4 1 2 3
 

Sample Output
  
  
7 5 3
 


错误代码:杭电AC不了

#include <stdio.h>
#include <iostream>
using namespace std;


int main()
{
    int i,j,t,n,sum;
    int input[100001],a[2];
    cin>>t;
    while(t--)
    {
        cin>>n;
        sum=2;
        for(i=0;i<n;i++)
        {
            cin>>input[i];
        }
if(input[0]<input[1])
{
a[0]=input[0];
a[1]=input[1];
}
else
{
a[0]=input[1];
a[1]=input[0];
}
        for(i=2;i<n;i++)
        {
            if(a[0]>=input[i])
            { 
                sum++;
                a[0]=input[i];
            }
            if(a[1]<=input[i])
            {
                sum++;
                a[1]=input[i];         
            }
        }
        cout<<sum<<endl;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值