A. Thanos Sort

本文介绍了一种名为Thanossort的排序算法,该算法通过不断移除数组的一半元素直至剩余部分有序。文章提供了一个实现示例,并解释了如何通过递归地检查数组的两半来确定最长有序子数组的长度。

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

题目链接
Thanos sort is a supervillain sorting algorithm, which works as follows: if the array is not sorted, snap your fingers* to remove the first or the second half of the items, and repeat the process.

Given an input array, what is the size of the longest sorted array you can obtain from it using Thanos sort?

*Infinity Gauntlet required.

Input
The first line of input contains a single number n (1≤n≤16) — the size of the array. n is guaranteed to be a power of 2.

The second line of input contains n space-separated integers ai (1≤ai≤100) — the elements of the array.

Output
Return the maximal length of a sorted array you can obtain using Thanos sort. The elements of the array have to be sorted in non-decreasing order.

input
4
1 2 2 4

output
4

input
8
11 12 1 2 13 14 3 4

output
2

input
4
7 6 5 4

output
1

Note
In the first example the array is already sorted, so no finger snaps are required.

In the second example the array actually has a subarray of 4 sorted elements, but you can not remove elements from different sides of the array in one finger snap. Each time you have to remove either the whole first half or the whole second half, so you’ll have to snap your fingers twice to get to a 2-element sorted array.

In the third example the array is sorted in decreasing order, so you can only save one element from the ultimate destruction.

题意: 给你一串数字,如果无序就进行两种操作,要么移除前一半,要么移除后一半,知道数组有序为止,输出最大的有序数组长度
题解:模拟 瞎搞一波

#include<bits/stdc++.h>
using namespace std;
int n,a[20];
int func(int l,int r){
	if(is_sorted(a + l,a + r + 1)) return r - l + 1;
	int mid = l + r >> 1;
	return max(func(l,mid),func(mid + 1,r));
}
int main(){		
	scanf("%d",&n);
	for(int i = 1;i <= n;i++) scanf("%d",a + i);
	printf("%d\n",func(1,n));
	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、付费专栏及课程。

余额充值