A. Thanos Sort
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 nn (1≤n≤161≤n≤16) — the size of the array. nn is guaranteed to be a power of 2.

The second line of input contains nn space-separated integers aiai (1≤ai≤1001≤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.

Examples
Input

Copy
4
1 2 2 4
Output

Copy
4
Input

Copy
8
11 12 1 2 13 14 3 4
Output

Copy
2
Input

Copy
4
7 6 5 4
Output

Copy
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<iostream>
using namespace std; int n ;
int a[];
int mmx(int x , int y)
{
int sum = ; //注意这里sum从1开始;因为一个数字就算是升序;
int flag = ;
for(int i = x ; i < y ;i++)
{
if(a[i]<=a[i+]) //看是否该序列已经升序;
{
sum++;
}else
{
flag = ; //一旦有不升序的就标记;
}
}
if(flag==)
{
return sum ;
}else
if(flag==) //不断递归;
{
int m = (x+y)/;
return max(mmx(x,m),mmx(m+,y));//取最大;
}
}
int main()
{
int ans = ;
cin>>n;
for(int i = ; i <= n ;i++)
{
cin>>a[i];
}
ans = mmx(,n);
cout<<ans;
}
 

April Fools Day Contest 2019 A. Thanos Sort的更多相关文章

  1. April Fools Day Contest 2019: editorial回顾补题

    A. Thanos Sort time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. April Fools Day Contest 2014

    April Fools Day Contest 2014 A.C.H三道题目 ============================================================= ...

  3. 坑爹CF April Fools Day Contest题解

    H - A + B Strikes Back A + B is often used as an example of the easiest problem possible to show som ...

  4. April Fools Day Contest 2014 H. A + B Strikes Back

    H. A + B Strikes Back time limit per test 1 second memory limit per test 256 megabytes input standar ...

  5. April Fools Day Contest 2016 D. Rosetta Problem

    D. Rosetta Problem 题目连接: http://www.codeforces.com/contest/656/problem/D Description ++++++++[>+& ...

  6. April Fools Day Contest 2016 G. You're a Professional

    G. You're a Professional 题目连接: http://www.codeforces.com/contest/656/problem/G Description A simple ...

  7. April Fools Day Contest 2016 F. Ace It!

    F. Ace It! 题目连接: http://www.codeforces.com/contest/656/problem/F Description Input The only line of ...

  8. April Fools Day Contest 2016 E. Out of Controls

    E. Out of Controls 题目连接: http://www.codeforces.com/contest/656/problem/E Description You are given a ...

  9. April Fools Day Contest 2016 C. Without Text 信号与系统

    C. Without Text 题目连接: http://www.codeforces.com/contest/656/problem/C Description You can preview th ...

随机推荐

  1. 众包高效实用的.NET开源项目

    1.Akka.NET: 概述:更轻松地构建强大的并发和分布式应用. 简介:Akka.NET是一个用于在.NET和Mono上构建高度并发,分布式和容错的事件驱动应用程序的工具包和运行时. 开源地址:ht ...

  2. 为什么要初始化css样式

    因为浏览器的兼容问题,不同浏览器对有些标签的默认值是不同的,如果没对CSS初始化往往会出现浏览器之间的页面显示差异. 初始化CSS样式主要是提高编码质量,如果不初始化整个页面做完很糟糕,重复的CSS样 ...

  3. 从excel、txt、dict中取data,预期值

    一:从excel中取data excel中放入预期值,上报data数据 excel中第一行是data数据,第二行是预期值 在每个class中,取data数据上报到接口中,具体代码如下: def get ...

  4. 聚类 高维聚类 聚类评估标准 EM模型聚类

    高维数据的聚类分析 高维聚类研究方向 高维数据聚类的难点在于: 1.适用于普通集合的聚类算法,在高维数据集合中效率极低 2.由于高维空间的稀疏性以及最近邻特性,高维的空间中基本不存在数据簇. 在高维聚 ...

  5. 什么是DA控制

    液压系统中的DA控制: Automotive Drive control & Anti stall control 自动变速控制 & 防熄火控制 (DA控制) 1:自动(变速)驱动控制 ...

  6. wordpress Bloginfo()函数

    bloinfo($show); ‘name‘ – 显示在 设置 > 常规 中设置的“站点标题”. 该数据是从 wp_options 这个数据表中检索到的 "blogname" ...

  7. CentOS-6.4 编译安装ffmpeg加x264以及rtmp

    CentOS 6.4-64位下编译ffmpeg几个简单步骤: 1.编译前环境准备: 2.下载源码: 3.编译,安装: ----------------------------------------- ...

  8. linux下的定时或计时操作(gettimeofday等的用法,秒,微妙,纳秒(转载)

    一.用select()函数实现非阻塞时的等待时间,用到结构体struct timeval {},这里就不多说了. 二.用gettimeofday()可获得微妙级(0.000001秒)的系统时间,调用两 ...

  9. spring中aop原理

  10. Linux的基本指令--

     VIM简介: Vi有三种基本工作模式 1.命令模式 2.文本输入模式 3. 末行模式 VIM基本操作: 一 . 进入插入模式: i: 插入光标前一个字符 I: 插入行首 a: 插入光标后一个字符 A ...