https://pintia.cn/problem-sets/994805342720868352/problems/994805427332562944

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

代码:

#include <bits/stdc++.h>
using namespace std; int N, M, K;
vector<int> v; int main() {
scanf("%d%d%d", &M, &N, &K);
while(K --) {
bool flag = false;
v.resize(N + 1);
int cnt = 1;
for(int i = 1; i <= N; i ++)
scanf("%d", &v[i]); stack<int> s;
for(int i = 1; i <= N; i ++) {
s.push(i);
if(s.size() > M) break;
while(!s.empty() && s.top() == v[cnt]) {
s.pop();
cnt ++;
}
} if(cnt == N + 1) flag = true;
if(flag) printf("YES\n");
else printf("NO\n");
}
return 0;
}

  感觉年就这么结束了诶

 

PAT 甲级 1051 Pop Sequence的更多相关文章

  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)(25 分)

    Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and p ...

  3. PAT甲级——A1051 Pop Sequence

    Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and p ...

  4. 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 ...

  5. 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 ...

  6. PAT 1051 Pop Sequence[栈][难]

    1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the order ...

  7. PAT 1051 Pop Sequence (25 分)

    返回 1051 Pop Sequence (25 分)   Given a stack which can keep M numbers at most. Push N numbers in the ...

  8. 1051. Pop Sequence

    原题连接:https://www.patest.cn/contests/pat-a-practise/1051 题目: Given a stack which can keep M numbers a ...

  9. 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 ...

随机推荐

  1. FFT && NTT板子

    贴板子啦-- FFT板子:luogu P3803 [模板]多项式乘法(FFT) #include<cstdio> #include<iostream> #include< ...

  2. 6、JVM--类文件结构(下)

    6.4 字节码指令简介 Java虚拟机的指令由一个字节长度的.代表着某种特定操作含义的数字(称为操作码,Opcode)以及跟随其后的零至多个代表此操作所需参数(称为操作数,Operands)而构成.由 ...

  3. Qt入门之基础篇 ( 一 ) :Qt4及Qt5的下载与安装

    转载请注明出处:CN_Simo. 导语: Qt是一个跨平台的C++图形界面应用程序框架.它提供给开发者建立图形用户界面所需的功能,广泛用于开发GUI程序,也可用于开发非GUI程序.Qt很容易扩展,并且 ...

  4. Lr场景设计-hc课堂笔记

    性能测试最基本也是最难的部分:场景设计.瓶颈分析和定位 10个业务10个脚本,每个脚本单独执行:单独场景.10个脚本一起执行:混合场景.10个业务1个脚本:可以设计不同用户登录,分别做不同的操作等场景 ...

  5. Python2.7-copy

    copy 模块,python 中的‘=’是使左边的对象成为右边对象的一个引用,对不可变对象(如数字,字符串等)使用‘=’一般不会出现问题,但当对字典,列表等可变对象进行‘=’操作时,要注意修改其中一个 ...

  6. 编写陈旭,实现通过字符型变量创建boolean值,再将其转换为字符串输出,观察输出后的字符串与创建Boolean对象时给定的参数是否相等.

    主要涉及到基本数据类型与包装类的转换. Boolean类的tostring方法的作用,返回一个表示该布尔值的 String 对象 public class Test1 { public static ...

  7. 浅谈 DNS

    一.DNS(Domain Name System,域名系统) 概念:万维网(WWW是环球信息网的缩写,亦作“Web”.“WWW”.“'W3'”,英文全称为“World Wide Web”),作为域名和 ...

  8. [笔记] ubuntu下添加windows的字体

    方法如下: 第一步:将windows下喜欢的字体文件copy到一个文件夹中,例如将XP里WINDOWS/FONTS中的字体文件(本人比较贪心,把整个文件夹copy了过来……),在linux中命名为xp ...

  9. Arduino入门笔记(2):Arduino的开发和virtualbreadboard仿真环境

    欢迎加入讨论群 64770604 1.开发环境 (1)下载开发环境 Arduino的开发环境从http://arduino.cc/en/Main/Software官网下载即可,分为windows版本. ...

  10. Web前端性能杂记

    前面说过,用户感受的响应时间是取决于诸多因素的,我们几乎不能得到真实的用户响应时间.对于Web应用前端性能的研究也不是为了准备得到一个响应时间,其性能一部分取决于Web服务器和应用服务器(下载资源,执 ...