stack permutation
#include <iostream>
#include <stack>
#include <queue>
using namespace std; bool checkSP(int in[], int out[], int n)
{
queue<int> input;
for(int i=;i<n;i++)
input.push(in[i]); queue<int> output;
for(int i=;i<n;i++)
output.push(out[i]); stack<int> temp;
while(!input.empty())
{
int elem = input.front();
input.pop();
if(elem == output.front())
{
output.pop();
while(!temp.empty())
{
if(temp.top() == output.front())
{
temp.pop();
output.pop();
}
else
break;
}
}
else
temp.push(elem);
}
return (input.empty()&&temp.empty());
} int main(){
int input[] = {,,};//<1,2,3]
int output[] = {,,};//<3,1,2]
int n = ;
if(checkSP(input, output, n))
cout << "YES";
else
cout << "NO";
return ;
}

stack permutation的更多相关文章
- 60. Permutation Sequence
题目: The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of t ...
- LeetCode Palindrome Permutation II
原题链接在这里:https://leetcode.com/problems/palindrome-permutation-ii/ 题目: Given a string s, return all th ...
- Codeforces Round #309 (Div. 1) B. Kyoya and Permutation 构造
B. Kyoya and Permutation Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
- Codeforces554D:Kyoya and Permutation
Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct ...
- Swaps in Permutation
Swaps in Permutation You are given a permutation of the numbers 1, 2, ..., n and m pairs of position ...
- 123 A. Prime Permutation
链接 http://codeforces.com/contest/123/problem/A 题目 You are given a string s, consisting of small Lati ...
- [Codeforces 864D]Make a Permutation!
Description Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to ...
- [Swift]LeetCode946. 验证栈序列 | Validate Stack Sequences
Given two sequences pushed and popped with distinct values, return true if and only if this could ha ...
- Codeforces Round #436 (Div. 2)D. Make a Permutation! 模拟
D. Make a Permutation! time limit per test: 2 seconds memory limit per test: 256 megabytes input: st ...
随机推荐
- JQ中的FormData对象 ajax上传文件
HTML代码: <form enctype="multipart/form-data" method="POST" name="searchfo ...
- Docker 简单运用
Docker 帮助系统管理员和程序员在容器中开发应用程序,并且可以扩展到成千上万的节点,容器和 VM(虚拟机)的主要区别是,容器提供了基于进程的隔离,而虚拟机提供了资源的完全隔离.虚拟机可能需要一分钟 ...
- andriod导入v4包导致的错误
最近升级android studio到版本3.0.1后,想要使用FragmentActivity这个类,导入v4包,发现R文件报错了,也就是找不到的意思. 如图:导包 此时选中v4包导进去. 确定之后 ...
- [poj 2479] Maximum sum -- 转载
转自 CSND 想看更多的解题报告: http://blog.csdn.net/wangjian8006/article/details/7870410 ...
- pyqt5加载网页的简单使用
如下初步使用了pyqt5,构造了一个webview来加载网址,呈现网页. 1.安装pyqt5包,可使用douban的源 pip install pyqt5 -i http://pypi.douban. ...
- Python学习---重点模块之xml
xml是实现不同语言或程序之间进行数据交换的协议,跟json差不多,但json使用起来更简单 数据准备 <?xml version="1.0"?> <data&g ...
- Win7系统托盘解决出现CH图标的方法
中文环境下,使用的英文键盘应该是“中文(简体)-美式键盘",这个输入法虽然是用来打英文的,但是归到中文类的,对应就是CH 如果因为某些不知明原因,增加了"美式键盘"等其他 ...
- yii2.0数据库查询修改等方法
yii2.0学习有一段时间了,给大家分享一下一些简单的查询等如何操作. 查询:(这里最前面的Test是引用的模型名) Test::find()->all(); 此方法返回所有数据: Tes ...
- 「FJ2014集训 采药人的路径」
题目 考虑一下把\(0\)看成\(-1\),那么就是找到一条边权和为\(0\)的路径,且这条路径可以被分成两段,边权和都是\(0\) 没有第二个限制就是点分裸题了 其实有了第二个限制还是点分裸题 考虑 ...
- luogu P3950 部落冲突
嘟嘟嘟 树剖板子题. #include<cstdio> #include<iostream> #include<algorithm> #include<cma ...