April Fools Day Contest 2019 A. Thanos Sort
1 second
256 megabytes
standard input
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.
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.
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.
4
1 2 2 4
4
8
11 12 1 2 13 14 3 4
2
4
7 6 5 4
1
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的更多相关文章
- April Fools Day Contest 2019: editorial回顾补题
A. Thanos Sort time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- April Fools Day Contest 2014
April Fools Day Contest 2014 A.C.H三道题目 ============================================================= ...
- 坑爹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 ...
- 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 ...
- April Fools Day Contest 2016 D. Rosetta Problem
D. Rosetta Problem 题目连接: http://www.codeforces.com/contest/656/problem/D Description ++++++++[>+& ...
- 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 ...
- 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 ...
- 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 ...
- April Fools Day Contest 2016 C. Without Text 信号与系统
C. Without Text 题目连接: http://www.codeforces.com/contest/656/problem/C Description You can preview th ...
随机推荐
- js操作serviceWorker缓存静态文件
js操作serviceWorker缓存静态文件 serviceWorker的作用就是用来做离线应用的,在手机端程序中用的较多 先看下效果 index.html <!DOCTYPE html> ...
- Bokeh绘图
http://bokeh.pydata.org/en/latest Bokeh 是一个专门针对Web浏览器的呈现功能的交互式可视化Python库.这是Bokeh与其它可视化库最核心的区别. 专门针对 ...
- el表达式动态拼接变量_c:set的用法
转自:https://blog.csdn.net/xb12369/article/details/39581955如 何在${}中使用${},例:${user.name_${user.id}},use ...
- iTunes 安装ipa文件到iPhone上
iTunes 安装ipa文件到iPhone上 把ipa文件拖到itunes里面. ipa(iPhoneApplication) 菜单 File>Add File to Library>Se ...
- django dynamic model
django model 首先对于一个习惯用django model的骚年来说,你肯定对django model自定制用的很熟悉,但突然让你用django dynamic model,也许会有很多人懵 ...
- Ant之build.xml详解---可用
Ant的概念 :在Eclipse中使用Ant Ant是Java平台下非常棒的批处理命令执行程序,能非常方便地自动完成编译,测试,打包,部署等等一系列任务,大大提高开发效率. Ant和make命令很像. ...
- elasticsearch配置小记(转)
原文 http://bigbo.github.io/pages/2015/04/10/elasticsearch_config/ 基于 elasticsearch 1.4.4 版本.安装方式为RPM ...
- 面试中的C++常见问题
1.在C++ 程序中调用被C 编译器编译后的函数,为什么要加extern “C”? 答:首先,extern是C/C++语言中表明函数和全局变量作用范围的关键字,该关键字告诉编译器,其声明的函数和变量可 ...
- 虚拟机Ubuntu16.04安装lrzsz
[系统环境] 宿主机:Win7 64位 虚拟机软件:Vmware workstation 12 虚拟机:Ubuntu 16.0.4 [目的] 配合Secure CRT使用rz,sz,方便在Ubuntu ...
- 在CenOS7.5里安装Redis
一.系统环境 操作系统:CentOS 7.5 Redis版本:redis3.2.8 登录账号:Frank 二.安装过程 A.预安装,安装gcc 1.进入终端,切换到root账号 2.输入指令: yum ...