1145A. Thanos Sort

本文介绍了一个CodeForces上的题目1145A的解题思路与实现方法,通过递归查找最长递增子序列,满足特定移除规则下最大长度。使用C++实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原题链接:http://codeforces.com/problemset/problem/1145/A

题意:给出一组数字,求最长从小到大排列的数字序列,要求:若当前序列中存在a[i] > a[j] (i<j),则将整个数组前半部分去除或将后半部分去除,直到剩余数组中所有的数都是按照从小到大的顺序排列的,求这种情况下的最大剩余数字长度。

分析:因为每次需要判断当前数组段中是否存在a[i] > a[j] (i<j)的情况,而且给出的范围n是(1<=n<=16),因此递归判断每一次的数组段是否满足要求即可。

#include<bits/stdc++.h>
using namespace std;

int maxlen;///记录最大段长
void finds(int a[],int st, int ed)///数组a,当前数组段起点,终点
{
    int fg = 0;
    if(ed-st==0)///若ed==st 说明当前段长为1
    {
        if(maxlen==0)maxlen=1;///当所有满足条件段长均为1时,该判断其作用
        return ;///出口1
    }
    for(int i = st;i<ed;i++)///判断
    {
        if(a[i]>a[i+1])
        {
            fg = 1;
            break;
        }
    }
    if(fg==0)
    {
        if(maxlen<ed-st+1)maxlen = ed-st+1;
        return ;///当前段满足条件,出口2
    }else
    {
        finds(a,st,(st+ed)/2);///递归求解
        finds(a,(st+ed)/2+1,ed);
    }

}

int main()
{
    int n;
    int a[20];
    maxlen = 0;
    cin>>n;
    for(int i =0 ; i < n; i++)cin>>a[i];
    finds(a,0,n-1);
    cout<<maxlen<<endl;

    return 0;

}

 

com.tongweb.deploy.interfaces.DeployException: com.tongweb.deploy.interfaces.DeployException: com.tongweb.web.thanos.startup.DeployInnerWebtierException: com.tongweb.web.thanos.startup.DeployInnerWebtierException: java.lang.IllegalStateException: ContainerBase.addChild: start: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.ruoyi.RuoYiApplication]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'docTableServiceImpl' for bean class [com.ruoyi.system.service.impl.DocTableServiceImpl] conflicts with existing, non-compatible bean definition of same name and class [com.ruoyi.oracle.service.impl.DocTableServiceImpl]--------this exception is deploy,exception occur is in exceptionWebtierInnerPhaserootcause is java.lang.IllegalStateException: ContainerBase.addChild: start: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.ruoyi.RuoYiApplication]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'docTableServiceImpl' for bean class [com.ruoyi.system.service.impl.DocTableServiceImpl] conflicts with existing, non-compatible bean definition of same name and class [com.ruoyi.oracle.service.impl.DocTableServiceImpl]--------this exception is deploy,exception occur is in exceptionWebtierInnerPhaserootcause is com.tongweb.web.thanos.startup.DeployInnerWebtierException: java.lang.IllegalStateException: ContainerBase.addChild: start: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.ruoyi.RuoYiApplication]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'docTableServiceImpl' for bean class [com.ruoyi.system.service.impl.DocTableServiceImpl] conflicts with existing, non-compatible bean definition of same name and class [com.ruoyi.oracle.service.impl.DocTableServiceImpl]--------this exception is deploy,exception occur is in exceptionWebtierInnerPhaserootcause is java.lang.IllegalStateException: ContainerBase.addChild: start: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.ruoyi.RuoYiApplication]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'docTableServiceImpl' for bean class [com.ruoyi.system.service.impl.DocTableServiceImpl] conflicts with existing, non-compatible bean definition of same name and class [com.ruoyi.oracle.service.impl.DocTableServiceImpl]--------this exception is deploy,exception occur is in exceptionWrapperPhase-------报这个错了
最新发布
04-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值