HDU6215
Brute Force Sorting
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1204 Accepted Submission(s): 314
Problem Description
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.
Input
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],⋯,A[N] where each integer A[i] satisfies 1≤A[i]≤100000.
Output
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.
Sample Input
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
Sample Output
1 2 3 4 5
0
2
1 2
2
1 3
3
2 3 5
Source
//2017-09-19
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = ; int a[N], n;
int _next[N], _pre[N];
int head, tail, que[N<<]; int main()
{
int T;
scanf("%d", &T);
while(T--){
scanf("%d", &n);
tail = ;
for(int i = ; i <= n; i++){
scanf("%d", &a[i]);
_next[i] = i+;
_pre[i] = i-;
que[tail++] = i;
}
a[] = ;
a[n+] = N;
_pre[] = ;
_next[] = ;
_pre[n+] = N;
_next[n+] = n+;
int ans = n, fg = , ptr;
while(fg){
fg = ;
head = ;
ptr = ;
while(head < tail){
int cnt = , i = que[head];
for(; i <= n; i = _next[i]){
if(a[i] > a[_next[i]]){
cnt++;
fg = ;
}else break;
}
if(cnt){
ans -= cnt+;
_next[_pre[que[head]]] = _next[i];
_pre[_next[i]] = _pre[que[head]];
que[ptr++] = _pre[que[head]];
};
while(que[head] <= i && head < tail)head++;
}
tail = ptr;
}
if(ans < )ans = ;
printf("%d\n", ans);
for(int i = _next[]; i <= n; i = _next[i]){
if(_next[i] != N)printf("%d ", a[i]);
}
printf("\n");
} return ;
}
HDU6215的更多相关文章
- Brute Force Sorting(HDU6215)
题意:给你长度为n的数组,定义已经排列过的串为:相邻两项a[i],a[i+1],满足a[i]<=a[i+1].我们每次对当前数组删除非排序过的串,合并剩下的串,继续删,直到排序完成. 题解:用双 ...
- hdu6215 Brute Force Sorting
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6215 题目: Brute Force Sorting Time Limit: 1000/100 ...
- hdu6215 Brute Force Sorting(模拟)
题意 给一个长度为n(n<=1e5)的序列,如果一个位置i满足a[i-1]>a[i]或者a[i]>a[i+1],那么我们就称该位置是不合法的位置 先把序列中所有不合法的位置统一找出来 ...
随机推荐
- 关不掉的小姐姐程序python tkinter实现 学习---打包教程
首先,我们先准备两个.py文件,还要图片文件 代码//是我自己手写的,copy时记得删掉,不然有可能错误,比如中英文啥的 当然 一些语法的无问题就百度,都能给你答案 第一个.py ...
- django自定义user认证系统
第一种,彻底推翻django的user认证系统,重新定义我们想要的字段 from django.contrib.auth.models import AbstractBaseUser,Permissi ...
- .NET Core微服务之路:让我们对上一个Demo通讯进行修改,完成RPC通讯
最近一段时间有些事情耽搁了更新,抱歉各位了. 上一篇我们简单的介绍了DotNetty通信框架,并简单的介绍了基于DotNetty实现了回路(Echo)通信过程. 我们来回忆一下上一个项目的整个流程: ...
- Unity面试题2
1.Animation.CrossFade命令作用是(C) A 动画消失 B动画转换 C东环的淡入为其他动画 2.Application.loadedLevel命令为(A) A加载关卡 B异步加载关卡 ...
- [Unity插件]DOTween基础
官方文档链接:http://dotween.demigiant.com/documentation.PHP#globalSettings 普通版下载地址:http://dotween.demigian ...
- create-react-app创建的项目npm run build之后静态文件找不到
create-react-app创建的项目npm run build之后,运行build中的index.html,什么都没显示,打开浏览器的F12,发现了几个红色的报错,提示几个文件找不到. 查看生成 ...
- 读取.Properties文件以及Spring注解读取文件内容
public class Main { public static void main(String[] args) throws IOException { //创建Properties对象 Pro ...
- Data - References
01 - 数据分析与数据挖掘的知识列表 图解 知识列表 |关注方面|初级数据分析师|高级数据分析师|数据挖掘工程师| |--------|--------|--------|--------| | 数 ...
- LeetCode: 150_Evaluate Reverse Polish Notation | 分析逆波兰式 | Medium
题目: Evaluate Reverse Polish Notation Evaluatethe value of an arithmetic expression in Reverse Polish ...
- Origin的使用问题集锦
在空间上看见同学转的一篇关于学术研究的文章,由于不常常上空间,更别说在上面看一些好的文章,所以特意将那篇文章整理到自己的博客中,方便以后做科研的时候能够用到,原文出处:http://user.qzon ...