【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 ...
随机推荐
- IntelliJ IDEA 2017.3尚硅谷-----主题
http://www.riaway.com/
- 左偏树(p4431)
难得不是左偏树,而是思维: 这道题在做得时候,有两个性质 1.如果a是一个不下降序列,那么b[i]==a[i]时取得最优解. 2.如果a是一个严格递减序列,则取a序列的中位数x,令b[1]=b[2]= ...
- [lua]紫猫lua教程-命令宝典-L1-01-03. 数值数据
lua5.3在线手册地址 https://cloudwu.github.io/lua53doc/contents.html#contents 其实我们直接啃手册就够了 推荐如果有基础的先啃手册再看紫 ...
- 每天进步一点点------Altium Designer PCB设计规则中英对照
Electrical(电气规则) Clearance:安全间距规则 Short Circuit:短路规则 UnRouted Net:未布线网络规则 UnConnected Pin:未连线引脚规则 Ro ...
- 117. 填充每个节点的下一个右侧节点指针 II
Q: 给定一个二叉树 struct Node { int val; Node *left; Node *right; Node *next; } 填充它的每个 next 指针,让这个指针指向其下一个右 ...
- 一份比较详细的DOS命令说明
一份比较详细的DOS命令说明 1 echo 和 @ 回显命令 @ #关闭单行回显 echo off #从下一行开始关闭回显 @echo ...
- Spring-boot JDBC with multiple DataSources sample
Spring-Boot's auto-configurer seems good for simple applications. For example it automatically creat ...
- mybatis批量插入和更新
批量插入 <insert id="add" parameterType="java.util.List"> insert all <forea ...
- django之orm的高级操作以及xcc安全攻击
查询用法大全: 1. 比较运算符 # id > 3 res = models.UserInfo.objects.filter(id__gt=3) # id >= 3 res = model ...
- 如何利用wx.request进行post请求
1,method 是 get 方式的时候,会将数据转换成 query string method 为 post 时,header为{"Content-Type": " ...