题意:

输入三个正整数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. 做新时代的奋斗者!(好吧,我还没弄出python的编译环境)

    Pictures: 今日分来的补记来嘞: Game 1:Guess the number. Python包含许多内建的函数,有些函数存在于称为模块的单独的程序中,可以使用import语句把它们的模块导 ...

  2. C#堆和栈的入门理解

    声明:以下内容从网络整理,非原创,适当待入个人理解. 解释1.栈是编译期间就分配好的内存空间,因此你的代码中必须就栈的大小有明确的定义:堆是程序运行期间动态分配的内存空间,你可以根据程序的运行情况确定 ...

  3. Java compareTo的用法

    compareTo() 方法用于将 Number 对象与方法的参数进行比较.可用于比较 Byte, Long, Integer等. 该方法用于两个相同数据类型的比较,两个不同类型的数据不能用此方法来比 ...

  4. Java - 字符串操作

    字符串常用操作如下 public static void main(String[] args) { /** * 创建字符串 */ String s1="zifuchuan123" ...

  5. stl队列

    队列(Queue)也是一种运算受限的线性表,它的运算限制与栈不同,是两头都有限制,插入只能在表的一端进行(只进不出),而删除只能在表的另一端进行(只出不进),允许删除的一端称为队尾(rear),允许插 ...

  6. Bug搬运工-CSCux99539:Intermittent error message "Power supply 2 failed or shutdown"

    Description Symptom:Following error messages will be seen intermittently.%PFMA-2-PS_FAIL: Power supp ...

  7. Maven - skiptest

    1. 概述 maven install 中尝试跳过 单元测试 2. 背景 从别处找来的工程 改了改发现测试过不了 编译都过不了 但又要着急继续调整 就是懒 这种事本来不提倡, 但是生产里数不胜数 Ma ...

  8. MYSQL的索引类型:PRIMARY, INDEX,UNIQUE,FULLTEXT,SPAIAL 区别与使用场合

    normal 普通索引   unique 唯一的,不允许重复的索引 该字段信息保证不会重复例如身份证号用作索引时,可设置为unique full textl 全文搜索的索引 FULLTEXT 用于搜索 ...

  9. .NET core 部署到Docker +Docker Protainer管理实现

    .NET core 部署到Docker +Docker Protainer管理实现 上次说到将.net core的应用程序发布到Linux中(https://www.cnblogs.com/Super ...

  10. console.log 如何打印对象

    问题描述: var obj={a:1,b:2}; console.log(obj); 控制台返回的值是object. 解决方案: console.log(JSON.stringify(obj))