题意:

输入三个正整数M,N,K(<=1000),分别代表栈的容量,序列长度和输入序列的组数。接着输入K组出栈序列,输出是否可能以该序列的顺序出栈。数字1~N按照顺序随机入栈(入栈时机随机,未知在何时入栈,可能在某个栈内元素出栈以后)。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[][];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int m,n,k;
cin>>m>>n>>k;
for(int i=;i<=k;++i){
for(int j=;j<=n;++j)
cin>>a[i][j];
int flag=;
stack<int>sk;
int top=;
for(int j=;j<=n;++j){
sk.push(j);
if(sk.size()>m&&!flag){
cout<<"NO\n";
flag=;
}
while(!sk.empty()&&sk.top()==a[i][top]){
sk.pop();
++top;
}
}
if(!sk.empty()&&!flag)
cout<<"NO\n";
else if(!flag)
cout<<"YES\n";
}
return ;
}

【PAT甲级】1051 Pop Sequence (25 分)(栈的模拟)的更多相关文章

  1. PAT 甲级 1051 Pop Sequence (25 分)(模拟栈,较简单)

    1051 Pop Sequence (25 分)   Given a stack which can keep M numbers at most. Push N numbers in the ord ...

  2. PAT 1051 Pop Sequence (25 分)

    返回 1051 Pop Sequence (25 分)   Given a stack which can keep M numbers at most. Push N numbers in the ...

  3. PAT Advanced 1051 Pop Sequence (25) [栈模拟]

    题目 Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, -, N and ...

  4. 【PAT】1051 Pop Sequence (25)(25 分)

    Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and p ...

  5. PAT 甲级 1051 Pop Sequence

    https://pintia.cn/problem-sets/994805342720868352/problems/994805427332562944 Given a stack which ca ...

  6. 1051 Pop Sequence (25分)

    Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and p ...

  7. 1051 Pop Sequence (25分)栈

    刷题 题意:栈的容量是5,从1~7这7个数字,写5个测试数据 做法:模拟栈 #include<bits/stdc++.h> using namespace std; const int m ...

  8. PAT 解题报告 1051. Pop Sequence (25)

    1051. Pop Sequence (25) Given a stack which can keep M numbers at most. Push N numbers in the order ...

  9. PTA 02-线性结构4 Pop Sequence (25分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/665 5-3 Pop Sequence   (25分) Given a stack wh ...

随机推荐

  1. nomon+ pyNmonAnalyzer实现基于python的nmon监控性能数据可视化

    pip install pyNmonAnalyzer nnmon  for linux from sourceforge:https://sourceforge.net/projects/nmon/ ...

  2. mongo日常命令集锦

    查询某个字段是否存在 db.student.findOne({name:{$exists:true}}) db.student.findOne({'department.name':{$exists: ...

  3. 树链剖分-Hello!链剖-[NOIP2015]运输计划-[填坑]

    This article is made by Jason-Cow.Welcome to reprint.But please post the writer's address. http://ww ...

  4. 主席树 模板题 luogu([POI2014]KUR-Couriers)

    求区间内是否有个数大于二分之一的数,有的话输出这个数,没有的话输出0. 在询问的时候,如果左边有sum大于这个limit,就可以继续求,如果右边有sum大于limit  也递归, 如果都不行,返回 0 ...

  5. new一个对象做了哪些操作

    网上其实有很多说new关键字做了哪些操作,读过之后就忘了,这里以自己的理解做一个简单的记录. function Naji () { this.skulk = function () { return ...

  6. 动手实现CapsNet系列——1 概述

    Geoffrey Hinton是深度学习的开创者之一,反向传播等神经网络经典算法发明人,他在17年年底和他的团队发表了两篇论文,介绍了一种全新的神经网络,这种网络基于一种称为胶囊(Capsule)的结 ...

  7. Qt 解析命令行参数

    #include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQuickView> ...

  8. 【Node.js安装步骤】

    "Node.js是一个Javascript运行环境(runtime environment),发布于2009年5月,由Ryan Dahl开发,实质是对Chrome V8引擎进行了封装.本文详 ...

  9. jmeter实现一次登录,多次业务请求(不同线程组间共享cookie和变量)

    实现目的 很多时候,在进行性能测试时,需要先登录,然后再对需求的事务进行相关性能测试,此时的登录操作,并不在本次性能测试的范围内,所以我们只需要登录一次,然后获取登录成功后的cookie等,并将coo ...

  10. git和github的关系以及简单易懂的理解

    git和github的关系   写在前面:我身边好多人问我git和github的区别,想必对于好多人没学过的大佬们恐怕也是一脸懵逼,但是不知道也是不行的,所以我今天就来讲一讲这二者的区别和联系. 用一 ...