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 ...
随机推荐
- python3在anaconda下安装caffe失败
Python 跟 Python3 完全就是两种语言 0x00 import caffe FAILED 环境为 Ubuntu 16 cuda 8.0 NVIDIA 361.77 Anaconda2.昨天 ...
- 聚合maven+spring-boot打包可执行jar
整整搞了一天,终于解决这个问题了.这里是四个module,module之间存在依赖,打包两个可执行jar,看下最终效果吧 聚合maven+spring-boot的搭建很简单,和普通的聚合maven没有 ...
- lua中的weak table
weakTable = {} weakTable[] = function() print("i am the first element") end weakTable[] = ...
- 用虚拟信用卡注册Google Play开发者账号
本文首发于http://www.abcdsxg.cn/free/net/562 虚拟信用卡 首先介绍一下虚拟信用卡(Virtual Credit Card),顾名思义,虚拟就是没有实体卡,一般都是在提 ...
- Oracle归档模式和非归档模式的区别
一.查看oracle数据库是否为归档模式: Sql代码1.select name,log_mode from v$database; NAME LOG_MODE ------------------ ...
- SQL Server ->> OFFSET & FETCH子句
SQL Server 2012引入OFFSET + FETCH字句.它俩出现在SELECT .... ORDER BY ...后面.作用是告诉SQL Server在结果集中忽略前N行然后取前M行出来. ...
- C#中的多线程 - 同步基础 z
原文:http://www.albahari.com/threading/part2.aspx 专题:C#中的多线程 1同步概要Permalink 在第 1 部分:基础知识中,我们描述了如何在线程上启 ...
- nginx 开启gzip压缩--字符串压缩比率很牛叉
刚刚给博客加了一个500px相册插件,lightbox引入了很多js文件和css文件,页面一下子看起来非常臃肿,所以还是把Gzip打开了. 环境:Debian 6 1.Vim打开Nginx配置文件 v ...
- IE浏览器兼容问题(下)——IE6的常见问题
IE6常见兼容性问题 1.盒模型问题 (1)DTD问题 DTD:文档定义类型,规定了要遵循的书写规范. 如果不写DTD,高级浏览器还是可以正常加载,IE6会以怪异模式进行加载. 盒模型:正常应该是外扩 ...
- 学习的矩阵微积分The matrix calculus you need for deep learning
学习的矩阵微积分The matrix calculus you need for deep learning https://explained.ai/matrix-calculus/index.ht ...