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. nios 使用count binary 例程 只是led不闪

    系统id有问题的总结: 1, 复位是否正确.(特别使用拨码开关的) 2, 硬件连接是否有问题.(SDRAM的时序约束可以有,也可以没有) 3, 引脚分配是否正确.(SDRAM的dqm就错过一次) 4, ...

  2. python's sixth day for me

    ---恢复内容开始--- #  ==  比较的是数值 a = 1000 b = 1000 print(a == b) #True #  is 比较的是内存地址 >>> a = 100 ...

  3. Python 小知识点(1)

    1.Python命名规则------>下划线连接    girl_of_wfb="lgl" 2.常量-----名称全大写->WFB="WFaceBoss&qu ...

  4. 只能在执行Render() 的过程中调用 RegisterForEventValidation;

    October 17, 2008  3:28 PMMarch 29, 2013  8:28 PM Aillo 编程   0 Comments 在实现"将GridView中的数据导出到Exce ...

  5. Oracle11gR2--删除数据库

    1. 停止ORACLE数据库 [oracle@localhost oracle]$ ps -ef|grep smon oracle 72550 1 0 14:23 ? 00:00:00 ora_smo ...

  6. Android Studio 配置模拟器AVD存放路径(默认在c盘,解决c盘空间不够问题)

    Android Studio 安装之后,默认的会给我们创建一个 Nexus 的模拟器, 这个模拟器的镜像文件放在了 C:\Users\Administrator\.android  中 其中的avd文 ...

  7. SpringSecurity3.X权限原理(转)

      这里给出一个简单的安全验证的实现例子,先说一下需求: 1.通过登录页面进行登录 2.用户登录前访问被保护的地址时自动跳转到登录页面 3.用户信息存储在数据表中 4.用户权限信息存在在数据表中 5. ...

  8. 中国大学MOOC 设置AutoCAD的绘图环境

  9. Angular24 树形菜单 ???

    待更新... 2018年5月21日15:17:47 参考博文01 参考博文02

  10. c语言实践 创建两个包含8个元素的double类型数组,第二个元素的每个元素的值都是对应前一个元素的前n个元素的和

    意思就是第二个元素的num[2]等于第一个元素的num[0]+num[1]+num[2] #define COUNT 8 int main(void) { double num1[COUNT]; do ...