http://acm.hdu.edu.cn/showproblem.php?pid=6215

题意:
给出一个序列,对于每个数,它必须大于等于它前一个数,小于等于后一个数,如果不满足,就删去。然后继续去判断剩下的数,直到最后都满足。

思路:

建立双向链表,如果一个数是需要删除的,那么它只会影响它前一个的数和后一个的数,这样只需要把它前面的数保存下来,下次再跑即可。

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,ll> pll;
const int INF = 0x3f3f3f3f;
const int maxn = +; int n ,top;
int a[maxn],pre[maxn],nxt[maxn];
int que[maxn]; template <class T>
inline void scan_d(T &ret)
{
char c;
ret = ;
while ((c = getchar()) < '' || c > '');
while (c >= '' && c <= '')
{
ret = ret * + (c - ''), c = getchar();
}
} int main()
{
//freopen("in.txt","r",stdin);
int T;
scan_d(T);
while(T--)
{
top=;
scan_d(n);
for(int i=;i<=n;i++)
{
scan_d(a[i]);
pre[i]=i-;
nxt[i]=i+;
que[top++]=i;
}
a[]=,a[n+]=INF;
nxt[]=,pre[n+]=n;
bool flag = true;
int ans = n;
while(flag)
{
int s = ;
flag = false;
int now = ;
while(now<top)
{
int cnt = ;
int it = que[now];
while(a[it]>a[nxt[it]]) {cnt++;it=nxt[it];flag=true;}
if(cnt)
{
ans-=(cnt+);
nxt[pre[que[now]]]=nxt[it];
pre[nxt[it]]=pre[que[now]];
que[s++]=pre[que[now]];;
}
while(que[now]<=it && now<top) now++;
}
top=s;
}
printf("%d\n",ans);
for(int i=;nxt[i]!=n+;i=nxt[i])
printf("%d ",a[nxt[i]]);
printf("\n");
}
return ;
}

HDU 6215 Brute Force Sorting(链表)的更多相关文章

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

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

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

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

  3. hdu 6215 Brute Force Sorting(模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6215 题解:类似双链表的模拟. #include <iostream> #include ...

  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. mongodb可视化工具 studio3t robo3T 下载安装使用介绍

    mongodb可视化工具 studio3t  robo3T 下载安装使用介绍 下载地址: https://studio3t.com/download robo3T

  2. VPS采用的几种常见技术(OVZ、Xen、KVM)介绍与对比

    很多人看到同样配置的VPS价格相差很大,甚是不理解,其实VPS使用的虚拟技术种类有很多,如OpenVZ.Xen.KVM.Xen和HVM与PV. 在+XEN中pv是半虚拟化,hvm是全虚拟化,pv只能用 ...

  3. httpclient get post

    https://www.cnblogs.com/wutongin/p/7778996.html post请求方法和get请求方法 package com.xkeshi.paymentweb.contr ...

  4. Linux下MySQL远程链接配置

    配置步骤: 1).首先进入数据库,使用系统数据库mysql mysql -u root -p mysql 2).接着对系统数据库的root账户设置远程访问的密码,与本地的root访问密码并不冲突 gr ...

  5. python初学者必看的学习路线

    Python是近几年比较火的编程语言之一,因为人工智能的火爆,让很多人都想从事python开发.很多零基础学员在学习python的时候都会走一些弯路,下面小编就为大家分享python学习路线图,帮助零 ...

  6. SpringMVC配置字符编码过滤器CharacterEncodingFilter来解决表单乱码问题

    1.GET请求 针对GET请求,可以配置服务器Tomcat的conf\server.xml文件,在其第一个<Connector>标签中,添加URIEncoding="UTF-8& ...

  7. kswapd0 进程CPU占用过高

    前几天遇到的一个问题,自己本地用VM配置的虚拟机,一般会top查看进程以及CPU占用的一些情况.又一次用laravel 打印对象,里面的内容比较多,浏览器当时就卡了. 然后看进程的情况.我以为会是ng ...

  8. 在虚拟机上安装gho、esd(wim)系统镜像文件

    gho.esd(wim)等文件不能被虚拟机识别,但如果把它们打包成iso就可以了. 另外,还需用到能在虚拟机上运行的WinPE的iso文件,本文用的是微PE. 注意:安装虚拟机提示operating ...

  9. 禁止单个IP或ip段访问

    //IP禁止判断接口,返回true则为找到 function checkIp($ip, $ipbanned) { $ipbannedFlag = false; if (!empty($ipbanned ...

  10. Tomcat 7服务器线程模型

    Tomcat 7服务器网络处理主要由NioEndpoint,其处理客户端连接的主要流程如图所示图中Acceptor及Worker分别是以线程池形式存在,Poller是一个单线程.注意,与BIO的实现一 ...