当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6215:Brute Force Sorting

题目描述
Beerus needs to sort an array of $N$ integers. Algorithms are not Beerus's strength. Destruction is what he excels. He can destroy all unsorted numbers in the array simultaneously. A number $A[i]$ of the array is sorted if it satisfies the following requirements.
1. $A[i]$ is the first element of the array, or it is no smaller than the left one $A[i-1]$.
2. $A[i]$ is the last element of the array, or it is no bigger than the right one $A[i+1]$.
In $[1,4,5,2,3]$, for instance, the element $5$ and the element $2$ would be destoryed by Beerus. The array would become $[1,4,3]$. If the new array were still unsorted, Beerus would do it again.
Help Beerus predict the final array.
输入解释
The first line of input contains an integer $T~(1\le T\le 10)$ which is the total number of test cases.
For each test case, the first line provides the size of the inital array which would be positive and no bigger than $100000$.
The second line describes the array with $N$ positive integers $A[1],A[2],\cdots,A[N]$ where each integer $A[i]$ satisfies $1\le A[i]\le 100000$.
输出解释
For eact test case output two lines.
The first line contains an integer $M$ which is the size of the final array.
The second line contains $M$ integers describing the final array.
If the final array is empty, $M$ should be $0$ and the second line should be an empty line.
输入样例
5
5
1 2 3 4 5
5
5 4 3 2 1
5
1 2 3 2 1
5
1 3 5 4 2
5
2 4 1 3 5
输出样例
5
1 2 3 4 5 
0

2
1 2 
2
1 3 
3
2 3 5 
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6215

最后修改于 2020-10-25T23:29:23+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000/1000MS(Java/Others) 65535/32768K(Java/Others)