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. spring mvc helloworld 和表单功能、页面重定向

    Spring MVC Hello World 例子 这里有个很好的教程:https://www.cnblogs.com/wormday/p/8435617.html 下面的例子说明了如何使用 Spri ...

  2. mysql字符类型

    字符类型 #官网:https://dev.mysql.com/doc/refman/5.7/en/char.html #注意:char和varchar括号内的参数指的都是字符的长度 #char类型:定 ...

  3. virsh使用qemu+tcp访问远程libvirtd

    因为ssh的不能访问 所以使用tcp进行对远程libvirtd进行连接访问,例如 virsh -c qemu+tcp://example.com/system 修改文件vim /etc/sysconf ...

  4. 01Javascript简介

    01 - Javascript 简介 web前端有三层: HTML:从语义的角度, 描述页面结构 CSS: 从审美的角度,描述样式(美化页面) JavaScript: 从交互的角度 , 描述行为(提升 ...

  5. hadoop 小知识点

    ------------------------------------------- 配置hadoop的最小blocksize,必须是512的倍数. [hdfs-site.xml] dfs.name ...

  6. CentOS Firewall简单使用

    启动 systemctl start firewalld 停止 systemctl stop firewalld 获取 firewalld 状态 firewall-cmd --state 在不改变状态 ...

  7. uboot重定位代码分析(转)

    概述 重定位(relocate)代码将BootLoader自身由Flash复制到SDRAM,以便跳转到SDRAM执行.之所以需要进行重定位是因为在Flash中执行速度比较慢,而系统复位后总是从0x00 ...

  8. 09-nginx Rewrite语法详解

    和location类似,也是要负责URL解析的. rewrite  重写 nginx的配置非常多,nginx的第三方模块也非常非常多.不可能讲每一种模块的配置办法.通常碰到一个nginx的新问题你想怎 ...

  9. 使用mail架包发送邮件javax.mail.AuthenticationFailedException: failed to connect at javax.mail.Service.connec

    这个错误是因为连接不上邮箱服务器导致的,可能有以下几个原因(以网易邮箱为例) 1.当使用第三方登录邮箱时需要有邮箱的授权码,且要开启POP3/SMTP/IMAP:服务 2.在代码中要调用网易邮箱的密码 ...

  10. 14.UNION 和 UNION ALL 操作符

    union all   union UNION 操作符用于合并两个或多个 SELECT 语句的结果集.请注意,UNION 内部的 SELECT 语句必须拥有相同数量的列.列也必须拥有相似的数据类型.同 ...