题意:

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

AAAAAccepted code:

  1. #define HAVE_STRUCT_TIMESPEC
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. int a[][];
  5. int main(){
  6. ios::sync_with_stdio(false);
  7. cin.tie(NULL);
  8. cout.tie(NULL);
  9. int m,n,k;
  10. cin>>m>>n>>k;
  11. for(int i=;i<=k;++i){
  12. for(int j=;j<=n;++j)
  13. cin>>a[i][j];
  14. int flag=;
  15. stack<int>sk;
  16. int top=;
  17. for(int j=;j<=n;++j){
  18. sk.push(j);
  19. if(sk.size()>m&&!flag){
  20. cout<<"NO\n";
  21. flag=;
  22. }
  23. while(!sk.empty()&&sk.top()==a[i][top]){
  24. sk.pop();
  25. ++top;
  26. }
  27. }
  28. if(!sk.empty()&&!flag)
  29. cout<<"NO\n";
  30. else if(!flag)
  31. cout<<"YES\n";
  32. }
  33. return ;
  34. }

【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. pandas 进行excel绘图

    python主流绘图工具:matplotlib ,seaborn,pandas ,openpyxl ,xslwriter openpyxl :首先说下这个官网的demo,看的有点懵,没有具体说明多个图 ...

  2. 安装VMware Tools和设置屏幕

    在虚拟机窗口的虚拟机-安装VMware Tools,点击安装,直到安装完成,出现以下界面 在主文件夹中新建VM文件夹,将VMware Tools中的VMwareTools-10.0.10-430167 ...

  3. np.c_与np.r_

    import sys reload(sys) sys.setdefaultencoding('utf-8') import numpy as np def test(): ''' numpy函数np. ...

  4. 2.2 selenium:org.openqa.selenium.WebDriverException: f.QueryInterface is not a function

    来源: http://blog.csdn.net/qiyueqinglian/article/details/47813271 URL中地址写不全的时候,就会报如题错误. url必须是完整的,比如ht ...

  5. 普通的javaweb项目和用maven管理的javaweb project的目录结构的区别

      图一,图二 这种就是单独的建立普通的(也就是没有用maven管理包)javaweb项目的结构目录,这种需要将普通的jar依赖放到lib目录下,之后通过bulid   图一

  6. Educational Codeforces Round 70 (Rated for Div. 2) 题解

    比赛链接:https://codeforc.es/contest/1202 A. You Are Given Two Binary Strings... 题意:给出两个二进制数\(f(x)\)和\(f ...

  7. Spring JdbcTemplate类常用的方法

    execute(String  sql) 可执行任何sql语句,但返回值是void,所以一般用于数据库的新建.修改.删除和数据表记录的增删改. int  update(String sql) int  ...

  8. css与js基础

    CSS样式 1 宽高设置 块元素可使用 wid 1字体 font-family :  文本类型 font-size     字体大小 font-style 字体样式 斜体italic   正常norm ...

  9. Multisim中'地'的问题

    1.地其实就是一个参考电压 对于示波器而言,只用连接一个探头,另一个探头默认就是连接地.

  10. Java面向对象编程 -6.4

    二维数组 数组的定义格式 数组的动态初始化:初始化之后数组中的每一个元素的保存的内容为其对应数据类型的默认值 声明并初始化数组: 数据类型 数组名称 [][] = new 数据类型[行个数][列个数] ...