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 ...
随机推荐
- 02_dubbo的SPI
[dubbo为什么不采用JDK自带的SPI] 1.JDK自带的SPI(ServiceLoader)会一次性实例化扩展点所有实现,基本只能通过遍历全部获取,也就是接口的实现类全部加载并实例化一遍,如果我 ...
- Http重要知识点
- 仿照jQuery进行一些简单的框架封装(欢迎指教~)
(function(window,undefined){ var arr = [], push = arr.push, slice = arr.slice; //首先要做的就是封装一个parseHtm ...
- Word 2010 去除文字或段落背景色
在复制网页文本到Word时,有时会带有网页上的背景颜色.下面采用两种方法解决这种问题,可根据不同需要进行选择. 方法一:清除样式 此种方法适用于只需要网页文字,而不想要网页任何样式信息,如字体大小,段 ...
- androidwebview网页显示事件
@Overridepublic void onPageCommitVisible(WebView view, String url) { super.onPageCommitVisible(view, ...
- android之键盘转载
显示键盘: EditText editText.setFocusable(true); editText.setFocusableInTouchMode(true); editText.request ...
- SpringMVC学习(三)——基于注解配置的springMVC项目
可运行的附件地址:http://files.cnblogs.com/files/douJiangYouTiao888/springWithAnnotation.zip 项目说明: 作者环境:maven ...
- png的故事:隔行扫描算法
转载自AlloyTeam:http://www.alloyteam.com/2017/06/the-story-of-png-deinterlacing-algorithm/ 前言 前文已经讲解过如何 ...
- WebRequest的get及post提交
static string get_html(string url) { var request = WebRequest.Create(url); var response = request.Ge ...
- Hadoop学习---Ubuntu中hadoop完全分布式安装教程
软件版本 Hadoop版本号:hadoop-2.6.0-cdh5.7.0: VMWare版本号:VMware 9或10 Linux系统:CentOS 6.4-6.5 或Ubuntu版本号:ubuntu ...