A. Thanos Sort

本文介绍了一种通过去除数组的前半部分或后半部分来寻找最长升序子序列的方法。利用枚举和递归两种方式实现算法,旨在解决特定问题,即在数组中找到按升序排列的最大子序列。

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

http://codeforces.com/problemset/problem/1145/

如果数组不是按照从小到大的顺序排列的话,就有两种操作1.去掉数组的前半部分(前面一半),2.去掉数组的后半部分(后面一半),如果数组还不是按照从小到大的顺序排列的话,重复上述操作,直到找到一个从小到大排的最大的序列;

枚举:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
#define ll long long
using namespace std;
int a[20];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=n;i>=1;i>>=1)//每次数组的长度都缩小一半,n是2的n次方
    {
        for(int j=0;j<n;j+=i)//枚举每一段
        {
            bool ans=1;
            for(int k=j+1;k<j+i;k++)
            {
                ans&=(a[k]>=a[k-1]);
            }
            if(ans){printf("%d\n",i);return 0;}//如果符合就输出,输出的结果一定是最长的
        }
    }
}

递归

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
#define ll long long
using namespace std;
int a[20];
int fun(int i,int j)
{
    if(is_sorted(a+i,a+j))
        return j-i;
    return max(fun(i,(i+j)/2),fun((i+j)/2,j));//找到前后两部分中最大的那个序列长度
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    printf("%d\n",fun(0,n));
}

 

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、付费专栏及课程。

余额充值