HDU 6215 Brute Force Sorting(链表)
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(链表)的更多相关文章
- HDU 6215 Brute Force Sorting(模拟链表 思维)
		
Brute Force Sorting Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
 - HDU 6215 Brute Force Sorting 模拟双端链表
		
一层一层删 链表模拟 最开始写的是一个一个删的 WA #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) mem ...
 - hdu 6215 Brute Force Sorting(模拟)
		
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6215 题解:类似双链表的模拟. #include <iostream> #include ...
 - hdu  6215 -- Brute Force Sorting(双向链表+队列)
		
题目链接 Problem Description Beerus needs to sort an array of N integers. Algorithms are not Beerus's st ...
 - HDU 6215 2017Brute Force Sorting 青岛网络赛 队列加链表模拟
		
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6215 题意:给你长度为n的数组,定义已经排列过的串为:相邻两项a[i],a[i+1],满足a[i]&l ...
 - 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 ...
 - hdu6215 Brute Force Sorting
		
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6215 题目: Brute Force Sorting Time Limit: 1000/100 ...
 - HDU 6215:Brute Force Sorting(链表+队列)
		
题目链接 题意 给出一个长度为n的数组,每次操作都要删除数组里面非递增的元素,问最终的数组元素有什么. 思路 容易想到用链表模拟删除,但是不能每次都暴力枚举,这样复杂度O(N^2).想到每次删除元素的 ...
 - hdu6215 Brute Force Sorting(模拟)
		
题意 给一个长度为n(n<=1e5)的序列,如果一个位置i满足a[i-1]>a[i]或者a[i]>a[i+1],那么我们就称该位置是不合法的位置 先把序列中所有不合法的位置统一找出来 ...
 
随机推荐
- Linux基础命令---ipcalc计算IP
			
ipcalc ipcalc提供了一种计算主机IP信息的简单方法.各种选项指定ipcalc应该在标准输出上显示什么信息.可以指定多个选项.必须始终指定要操作的IP地址.大多数操作还需要一个 ...
 - 转:[C# 开发技巧]如何防止程序多次运行
			
转载自:http://www.cnblogs.com/zhili/p/OnlyInstance.html 一.引言 最近发现很多人在论坛中问到如何防止程序被多次运行的问题的,如: http://soc ...
 - What’s WOYO PDR-007 Paintless Dent Repair Heat Induction?
			
when you car body with dent, which tools can fixing this problem? is there a device which with the c ...
 - Django后端项目---- rest framework(4)
			
一.分页 试问如果当数据量特别大的时候,你是怎么解决分页的? 方式a.记录当前访问页数的数据id 方式b.最多显示120页等 方式c.只显示上一页,下一页,不让选择页码,对页码进行加密 1.基于lim ...
 - K8S学习笔记之修改K8S的api-server证书
			
K8S的api-server证书包含很多IP和域名,有时候后期才发现证书内有错误,需要重新生成该证书. 修改server-csr.json,修改后基于原来的ca证书重新生成server.perm s ...
 - P1384 幸运数与排列
			
P1384 幸运数与排列 神奇的(逆)康托展开:求1到n的全排列中字典序第k小的排列 $k<=10^9<13!$,显然$k$最多只会影响后$13$位 前面一大串都是有序从小到大排列的,于是 ...
 - Python 操作 mysql数据库的一个小小的基础案例,小白新手,以备后用~~
			
model.py 中的代码 # Create your models here. # 书和作者一对多 class Author(models.Model): name = models.CharFie ...
 - 20145212 罗天晨 《网络对抗》Exp3 Advanced 恶意代码伪装技术实践
			
恶意代码伪装技术实践 木马化正常软件. 啊哈--原本以为很复杂--然后我看了一下蔡野同学的博客,发现原理竟然如此简单-- 对原先生成病毒的代码稍作修改: 于是--把生成的后门软件改成骗人的名字:这里改 ...
 - 对于ListView的一些用法(一)
			
ScrollView:只能用于控件比较少的界面,如果数据有上千上万条,那么使用ScrollView就不好了,因为ScrollView就把所有的控件进行初始化,这是非常消耗性能的操作,所以android ...
 - Java中单例设计模式,饿汉式和懒汉式
			
Java中单例模式是一种常见的设计模式,单例模式的写法有好几种,这里主要介绍三种:懒汉式单例.饿汉式单例.登记式单例. 单例模式有以下特点: 1.单例类只能有一个实例. 2.单例类必须自己创建自己的唯 ...