【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 ...
随机推荐
- DFT 问答 II
1. Boundary Scan A:Boundary scan 顾名思义,是附加在芯片I/O 周边的扫描测试链,它通过专门的测试端口(TAP)访问.在测试模式下,边界扫描链会接管功能逻辑,对I/O进 ...
- Lenet 神经网络-实现篇(1)
Lenet 神经网络结构为: ①输入为 32*32*1 的图片大小,为单通道的输入: ②进行卷积,卷积核大小为 5*5*1,个数为 6,步长为 1,非全零填充模式: ③将卷积结果通过非线性激活函数: ...
- 对象析构谈—— delete this 的使用及注意事项
this对象是必须是用 new操作符分配的(而不是用new[],也不是用placement new,也不是局部对象,也不是global对象): delete this后,不能访问该对象任何的成员变量及 ...
- C 语言实现面向对象编程
转载 https://blog.csdn.net/onlyshi/article/details/81672279 C 语言实现面向对象编程1.引言面向对象编程(OOP)并不是一种特定的语言或者工具, ...
- 移动端适配rem为单位的rem.js及个别设备设置了大字体模式,导致页面变形的处理方式
这段时间内,涉及到的都是移动端开发,说到移动端开发,我们就会思考到,目前分辨率的问题,如果用px为单位的话,在不同移动设备和不同分辨率下,页面的效果可能会有所不同,甚至导致页面变形.所以在次我们就用到 ...
- Java面向对象编程 -6.6
数组倒序 做法一:定义一个新的数组而后按照逆序的方式保存 public static void main(String[] args) { int arr[] = new int[] {1,2,3,4 ...
- 存储引擎:engine
1.表类型: 默认的服务器表类型,通过my.ini文件可以手动修改配置:default-storage- engine=INNODB 在创建表,或者编辑表时,可以指定表的存储引擎: 语法:engine ...
- C#常用集合
数组的缺点:长度固定.因此引入集合的使用. 注:泛型集合更安全,性能更高. 常用集合 对应泛型 ①动态数组ArrayList List<T> 常用方法属性:Add Clear C ...
- 京东秒杀抢购的小脚本和chorme的一个开发者插件
chorme开发者插件 下载源码包:https://github.com/gongjunhao/seckill/archive/master.zip 解压:seckill-master.zip 打开c ...
- phpinfo(): It is not safe to rely on the system's timezone settings
PHP调试的时候出现了警告: 问题: Warning: phpinfo(): It is not safe to rely on the system's timezone settings. You ...