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 ...
随机推荐
- XPath路径表达式笔记(转载)
简单说,xpath就是选择XML文件中节点的方法. 所谓节点(node),就是XML文件的最小构成单位,一共分成7种. - element(元素节点)- attribute(属性节点)- text ( ...
- xunsearch bsd 10.1安装心酸路。。。
cc -c -I/usr/local/xunsearch/include/ test.cpp cc test.o -L/usr/local/xunsearch/lib -lscws -lm -o te ...
- qt 使用qtxlsx 读写excel
https://github.com/dbzhang800/QtXlsxWriter 下载qtxlsx地址 QtXlsx is a library that can read and write Ex ...
- SQL UNION操作符使用
SQL UNION 操作符 SQL UNION 操作符合并两个或多个 SELECT 语句的结果. SQL UNION 操作符 UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意 ...
- web项目开发流程
对于一个web项目,在实际编码之前,有一些通用的步骤来planning a website: 0.Defining the project (predr0->dr0) 对于外部项目,客户一般会发 ...
- collectd的python插件(redis)
https://blog.dbrgn.ch/2017/3/10/write-a-collectd-python-plugin/ redis_info.conf <LoadPlugin pytho ...
- 【Leetcode】【Easy】Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...
- Exchange 2016系统要求
一.支持的共存方案 下表列出了一些支持 Exchange 2016 与 Exchange 早期版本共存的应用场景. Exchange 2016与Exchange Server早期版本共存 Exchan ...
- Yii2用Gii自动生成Module+Model+CRUD
1. 开启gii模块 common/config/main-local.php加入下面代码 return [ 'modules' => [ 'gii' => [ 'class' => ...
- WC2018 滚粗记
虽然又考炸了但还是总结一下.. $day0$:没有什么很重要的事.. $day1$:除了听(dong)课(mian)以外没有什么很重要的事.. $day2$:除了听(dong)课(mian)以外没有什 ...