【PAT甲级】1051 Pop Sequence (25 分)(栈的模拟)
题意:
输入三个正整数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 分)(栈的模拟)的更多相关文章
- 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 ...
- PAT 1051 Pop Sequence (25 分)
返回 1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the ...
- 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 ...
- 【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 ...
- PAT 甲级 1051 Pop Sequence
https://pintia.cn/problem-sets/994805342720868352/problems/994805427332562944 Given a stack which ca ...
- 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 ...
- 1051 Pop Sequence (25分)栈
刷题 题意:栈的容量是5,从1~7这7个数字,写5个测试数据 做法:模拟栈 #include<bits/stdc++.h> using namespace std; const int m ...
- 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 ...
- 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 ...
随机推荐
- pandas 进行excel绘图
python主流绘图工具:matplotlib ,seaborn,pandas ,openpyxl ,xslwriter openpyxl :首先说下这个官网的demo,看的有点懵,没有具体说明多个图 ...
- 安装VMware Tools和设置屏幕
在虚拟机窗口的虚拟机-安装VMware Tools,点击安装,直到安装完成,出现以下界面 在主文件夹中新建VM文件夹,将VMware Tools中的VMwareTools-10.0.10-430167 ...
- np.c_与np.r_
import sys reload(sys) sys.setdefaultencoding('utf-8') import numpy as np def test(): ''' numpy函数np. ...
- 2.2 selenium:org.openqa.selenium.WebDriverException: f.QueryInterface is not a function
来源: http://blog.csdn.net/qiyueqinglian/article/details/47813271 URL中地址写不全的时候,就会报如题错误. url必须是完整的,比如ht ...
- 普通的javaweb项目和用maven管理的javaweb project的目录结构的区别
图一,图二 这种就是单独的建立普通的(也就是没有用maven管理包)javaweb项目的结构目录,这种需要将普通的jar依赖放到lib目录下,之后通过bulid 图一
- Educational Codeforces Round 70 (Rated for Div. 2) 题解
比赛链接:https://codeforc.es/contest/1202 A. You Are Given Two Binary Strings... 题意:给出两个二进制数\(f(x)\)和\(f ...
- Spring JdbcTemplate类常用的方法
execute(String sql) 可执行任何sql语句,但返回值是void,所以一般用于数据库的新建.修改.删除和数据表记录的增删改. int update(String sql) int ...
- css与js基础
CSS样式 1 宽高设置 块元素可使用 wid 1字体 font-family : 文本类型 font-size 字体大小 font-style 字体样式 斜体italic 正常norm ...
- Multisim中'地'的问题
1.地其实就是一个参考电压 对于示波器而言,只用连接一个探头,另一个探头默认就是连接地.
- Java面向对象编程 -6.4
二维数组 数组的定义格式 数组的动态初始化:初始化之后数组中的每一个元素的保存的内容为其对应数据类型的默认值 声明并初始化数组: 数据类型 数组名称 [][] = new 数据类型[行个数][列个数] ...