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 pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. For example, if M is 5 and N is 7, we can obtain 1, 2, 3, 4, 5, 6, 7 from the stack, but not 3, 2, 1, 7, 5, 6, 4.
Input Specification:
Each input file contains one test case. For each case, the first line contains 3 numbers (all no more than 1000): M (the maximum capacity of the stack), N (the length of push sequence), and K (the number of pop sequences to be checked). Then K lines follow, each contains a pop sequence of N numbers. All the numbers in a line are separated by a space.
Output Specification:
For each pop sequence, print in one line "YES" if it is indeed a possible pop sequence of the stack, or "NO" if not.
Sample Input:
5 7 5
1 2 3 4 5 6 7
3 2 1 7 5 6 4
7 6 5 4 3 2 1
5 6 4 3 7 2 1
1 7 6 5 4 3 2
Sample Output:
YES
NO
NO
YES
NO
题目分析:一道模拟题 写了半天
#define _CRT_SECURE_NO_WARNINGS
#include <climits>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
stack<int> S1; int main()
{
int M, N, K;
cin >> M >> N >> K;
vector<int> Array(N+);
vector<int> Test(N+);
for (int i = ; i <= N; i++)
Array[i] = i;
for (int i = ; i < K; i++)
{
while (S1.size())
S1.pop();
for (int j = ; j <= N; j++)
cin >> Test[j];
int k = , t = ,flag=;
while (t<=N)
{
if (S1.size()> M)
{
flag = ;
break;
}
else if (S1.size())
{
if (S1.top() == Test[t])
{
S1.pop();
t++;
}
else if(k<=N)
{
S1.push(Array[k]);
k++;
}
else
{
if (S1.top() == Test[t])
{
S1.pop();
t++;
}
else
{
flag = ;
break;
}
}
}
else {
S1.push(Array[k]);
k++;
}
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
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甲级】1051 Pop Sequence (25 分)(栈的模拟)
题意: 输入三个正整数M,N,K(<=1000),分别代表栈的容量,序列长度和输入序列的组数.接着输入K组出栈序列,输出是否可能以该序列的顺序出栈.数字1~N按照顺序随机入栈(入栈时机随机,未知 ...
- 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 ...
- 【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 ...
- 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 ...
- 02-线性结构4 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 ...
随机推荐
- JavaScript入门进阶(二)
JavaScript进阶入门(二) 转换为数字 使用parseInt() parseInt函数会先查看位置0处的字符,如果该位置不是有效数字,则将返回NaN,如果0处的字符是数字,则将查看位置1处的字 ...
- 文本编辑器 - Sublime Text 3 换行无法自动缩进的解决方法
一.换行无法自动缩进的问题,如图: 稍微查了一下网上的办法,是把汉化文件删除,但是会造成菜单栏混乱,简直无法忍受... 那么这里介绍的是另一种解决办法.在用户的热键配置文件(preferences-k ...
- Java Grammar(二):运算符
运算符简介 计算机自打诞生以来,用作最多的就是进行计算,而计算离不开运算符,所以运算符在我们的Java语言中的地位举足轻重,我们现在就来了解一下Java给我们提供的运算符. 从运算的元素的个数来区分, ...
- ReentrantLock源码探究
ReentrantLock是一种可重入锁,可重入是说同一个线程可以多次获取同一个锁,内部会有相应的字段记录重入次数,它同时也是一把互斥锁,意味着同时只有一个线程能获取到可重入锁. 1.构造函数 pub ...
- 《自拍教程45》Python_adb实时监控Logcat日志
接上一篇:adb命令_一键截取logcat日志, 有一天, 系统稳定性开发负责人找到我,希望我能在跑android 系统monkey的时候, 实时监控logcat的输出,如果一旦发现"jav ...
- 初创电商公司Drop的数据湖实践
欢迎关注微信公众号:ApacheHudi 1. 引入 Drop是一个智能的奖励平台,旨在通过奖励会员在他们喜爱的品牌购物时获得的Drop积分来提升会员的生活,同时帮助他们发现与他们生活方式产生共鸣的新 ...
- PLINQ 并行操作Linq
C#并行编程-PLINQ:声明式数据并行 目录 C#并行编程-相关概念 C#并行编程-Parallel C#并行编程-Task C#并行编程-并发集合 C#并行编程-线程同步原语 C#并行编程-P ...
- HTML每日学习笔记(1)
7.15.2019 1.HTML脚本——JavaScript的嵌入使用,使 HTML 页面具有更强的动态和交互性. <script> 标签用于定义客户端脚本,比如 JavaScript. ...
- jenkins-gitlab-harbor-ceph基于Kubernetes的CI/CD运用(一)
注:这部分的学习还是要靠自己多点点 多尝试尝试 这部分19年3月份我是玩的很溜的,一年没用,基本忘光光了. 学习要温故而知新! 流程拓扑图 前提准备 部署应用服务 部署kubernetes 集群:ht ...
- Python-String字符串操作
name='xioer-pipo' print(name.capitalize()) #第一个字符大写 print(name.expandtabs()) print(name.count('o')) ...