E - Sequence in the Pocket

这是一个关于序列处理的编程挑战,输入包括两个整数和两个序列,程序需要找到序列B中不小于序列A中元素的最大长度子序列。提供的代码实现了这一逻辑,通过比较和计数找到满足条件的子序列长度。

传送门:Sequence in the Pocket
在这里插入图片描述
Sample Input

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

Sample Output

2
0

在这里插入图片描述
代码:

#include<bits/sdc++.h>
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        int a,b,c,d,m;
        scanf("%d",&a);
        m=0;
        int A[a+5];
        int B[a+5];
        int C[a+5];
        memset(A,0,sizeof(A));
        memset(B,0,sizeof(B));
        memset(C,0,sizeof(C));
        for(int i=0;i<a;i++){
            scanf("%d",&A[i]);
        }
        b=c=0;
        for(int i=0;i<a;i++){
            if(b==0||B[b-1]<=A[i]){
                B[b++]=A[i];
            }else{
                c++;
                m=max(m,A[i]);
            }
        }
        d=c;
        for(int i=0;i<b;i++){
            if(B[i]<m)
                d++;
            else
                break;
        }
        printf("%d\n",d);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值