题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6215

题解:类似双链表的模拟。

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int M = 1e5 + ;
int a[M] , Next[M] , pre[M] , que[M];
int main() {
int t;
scanf("%d" , &t);
while(t--) {
int n;
scanf("%d" , &n);
Next[] = ;
pre[n + ] = n;
int tot = ;
for(int i = ; i <= n ; i++) {
scanf("%d" , &a[i]);
que[tot++] = i;
Next[i] = i + ;
pre[i] = i - ;
}
int flag = ;
int ans = n;
while(!flag) {
flag = ;
int pos = ;
int useful = ;
while(pos < tot) {
int now = que[pos];
int cnt = ;
while(Next[now] <= n) {
if(a[now] > a[Next[now]]) now = Next[now] , cnt++ , flag = ;
else break;
}
if(cnt) {
ans -= (cnt + );
Next[pre[que[pos]]] = Next[now];
pre[Next[now]] = pre[que[pos]];
que[useful++] = pre[que[pos]];
}
while(que[pos] <= now && pos < tot) pos++;
}
tot = useful;
}
printf("%d\n" , ans);
int now = Next[];
while(ans--) {
printf("%d " , a[now]);
now = Next[now];
}
printf("\n");
}
return ;
}

hdu 6215 Brute Force Sorting(模拟)的更多相关文章

  1. HDU 6215 Brute Force Sorting 模拟双端链表

    一层一层删 链表模拟 最开始写的是一个一个删的 WA #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) mem ...

  2. HDU 6215 Brute Force Sorting(模拟链表 思维)

    Brute Force Sorting Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

  3. HDU 6215 Brute Force Sorting(链表)

    http://acm.hdu.edu.cn/showproblem.php?pid=6215 题意:给出一个序列,对于每个数,它必须大于等于它前一个数,小于等于后一个数,如果不满足,就删去.然后继续去 ...

  4. hdu 6215 -- Brute Force Sorting(双向链表+队列)

    题目链接 Problem Description Beerus needs to sort an array of N integers. Algorithms are not Beerus's st ...

  5. HDU 6215 2017Brute Force Sorting 青岛网络赛 队列加链表模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6215 题意:给你长度为n的数组,定义已经排列过的串为:相邻两项a[i],a[i+1],满足a[i]&l ...

  6. HDU - 6215 2017 ACM/ICPC Asia Regional Qingdao Online J - Brute Force Sorting

    Brute Force Sorting Time Limit: 1 Sec  Memory Limit: 128 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...

  7. hdu6215 Brute Force Sorting

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6215 题目: Brute Force Sorting Time Limit: 1000/100 ...

  8. HDU 6215:Brute Force Sorting(链表+队列)

    题目链接 题意 给出一个长度为n的数组,每次操作都要删除数组里面非递增的元素,问最终的数组元素有什么. 思路 容易想到用链表模拟删除,但是不能每次都暴力枚举,这样复杂度O(N^2).想到每次删除元素的 ...

  9. hdu6215 Brute Force Sorting(模拟)

    题意 给一个长度为n(n<=1e5)的序列,如果一个位置i满足a[i-1]>a[i]或者a[i]>a[i+1],那么我们就称该位置是不合法的位置 先把序列中所有不合法的位置统一找出来 ...

随机推荐

  1. Js 基础知识1

    JS比较运算符,有两种比较运算符: 第一种是==比较,它会自动转换数据类型再比较 第二种是===比较,它不会自动转换数据类型,如果数据类型不一致,返回false,如果一致,再比较. 不要使用==比较, ...

  2. Struts2 中Struts.xml结果页面配置

    结果页面的配置: 红色的比较常用 

  3. HttpClientFactory 使用说明 及 对 HttpClient 的回顾和对比

    目录 HttpClient 日常使用及坑点: HttpClientFactory 优势: HttpClientFactory 使用方法: 实战用法1:常规用法 1. 在 Startup.cs 中进行注 ...

  4. [nghttp2]压测工具,源码编译并进行deb打包过程

    编译环境:deepin 15.11桌面版 nghttp2下载地址:https://github.com/nghttp2/nghttp2 环境要求 emm只能在类Linux环境才能完整编译,想在Wind ...

  5. Spring Cloud 相关资料链接

    Spring Cloud中文网:https://springcloud.cc/ Spring Cloud API:https://springcloud.cc/spring-cloud-dalston ...

  6. 使用富文本编辑器Kindeditor

    今天在做需求的时候,遇到有一个字段,需要保存带有格式的内容,决定使用富文本框编辑器Kindeditor来实现,解决方法如下: 登录官网下载控件包: http://kindeditor.net/down ...

  7. python开发基础--思维导图

    开始学习python,相当于零基础 非自学,自学的痛苦不想体会和尝试,毕竟不会很友好,知乎上看到很多说自学的好处啊噼里啪啦的.嗯,说的很对,但是我偏不听,略略略.锻炼我的自学能力,这还需要锻炼吗,百度 ...

  8. (16)ASP.NET Core 通用主机(HostBuilder)

    1.前言 ASP.NET Core应用程序可以配置和启动主机(Host).主机负责应用程序启动和生命周期管理.通用主机用于无法处理HTTP请求的应用程序.通用主机的用途是将HTTP管道从Web主机AP ...

  9. 【0731 | Day 5】Python基础(三)

    Part 10 格式化输出的三种方式 一.占位符 #一般字符串连接/普通形式 ​ name = 'Adela' age = str(22) print('My name is '+ name+ ',' ...

  10. SpringBoot操作ES进行各种高级查询

    SpringBoot整合ES 创建SpringBoot项目,导入 ES 6.2.1 的 RestClient 依赖和 ES 依赖.在项目中直接引用 es-starter 的话会报容器初始化异常错误,导 ...