#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的更多相关文章

  1. 60. Permutation Sequence

    题目: The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of t ...

  2. LeetCode Palindrome Permutation II

    原题链接在这里:https://leetcode.com/problems/palindrome-permutation-ii/ 题目: Given a string s, return all th ...

  3. 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/ ...

  4. Codeforces554D:Kyoya and Permutation

    Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct ...

  5. Swaps in Permutation

    Swaps in Permutation You are given a permutation of the numbers 1, 2, ..., n and m pairs of position ...

  6. 123 A. Prime Permutation

    链接 http://codeforces.com/contest/123/problem/A 题目 You are given a string s, consisting of small Lati ...

  7. [Codeforces 864D]Make a Permutation!

    Description Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to ...

  8. [Swift]LeetCode946. 验证栈序列 | Validate Stack Sequences

    Given two sequences pushed and popped with distinct values, return true if and only if this could ha ...

  9. 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 ...

随机推荐

  1. servlet中cookie和session操作

    1.1 软件中的会话 一次会话: 打开浏览器 -> 访问一些服务器内容 -> 关闭浏览器 登录场景: 打开浏览器 -> 浏览到登陆页面 -> 输入用户名和密码 -> 访问 ...

  2. 老生常谈:++a与a--区别

    a++的作用是先对a进行操作再++:a--则相反. 如: int a = 1;int b = a++; //此时先运算b=a,再a++,故b=1,a=2int c = --a; //此时先--a,再运 ...

  3. 大规模WEB服务技术

    CPU负载的扩展很简单,增加相同结构的服务器,通过负载均衡来分散. I/O负载的扩展很困难.要考虑局部性.

  4. c++ 读写结构体到文件

    可以使用fwrite()将一个结构体写入文件:  fwrite(&some_struct,sizeof somestruct,1,fp);对应的fread函数可以再把它读出来,此处fwrite ...

  5. Porting QML Applications to Qt 5

    When porting QML-related code from Qt 4.8 to Qt 5, application developers should be aware that the Q ...

  6. Surrounded Regions [未完成]

    思路完全一样 AC的代码: class Solution { private: struct Point { int x, y; Point(int _x, int _y):x(_x), y(_y) ...

  7. 实现UILabel渐变色效果

    实现UILabel渐变色效果 效果如下图: 源码: // // CombinationView.h // ChangeColorLabel // // Created by YouXianMing o ...

  8. 对std::map进行排序

    1.对Key排序. std::map的第三个参数即为对key进行排序的比较函数.默认为less,表示升序.如果要降序,可以改为greater. 2.对Value排序 不支持,因为map不是一个序列的容 ...

  9. February 17 2017 Week 7 Friday

    The very essence of romance is uncertainty. 浪漫的精髓就在于它充满种种可能. If you want a happy life with enduring ...

  10. SqlParameter.Value = NULL 引发的数据库异常

    摘自:http://www.cnblogs.com/ccweb/p/3403492.html using (SqlCommand cmd = new SqlCommand()) { cmd.Conne ...