模拟栈的过程,一开始我是用的cin来判断每行的每一个数字,然后判断回车结束。有一个点会超时,答案用数组先记录序列的方法非常好。有一个注意点就是访问s.top()的时候先要保证s。size()>0,这点和数组是一样的。

#include<bits/stdc++.h>
using namespace std;
int m,n,k;
int arr[];
int main()
{
stack<int>st;
scanf("%d %d %d", &m, &n, &k);
int i;
while (k--)
{
bool flag = true;
int current = ;
for (i = ; i <= n; i++)
{
scanf("%d", &arr[i]);
}
while (!st.empty())
{
st.pop();
}
for (i = ;i<=n; i++)
{
st.push(i);
if (st.size()>m)
{
flag = false;
break;
}
while (current <= n&&st.size()>&&st.top() == arr[current])
{
st.pop();
current++;
}
}
if (st.size() == && flag == true)
{
printf("YES\n");
}
else
printf("NO\n");
}
}

pat 1051Pop Sequence的更多相关文章

  1. PAT Perfect Sequence (25)

    题目描写叙述 Given a sequence of positive integers and another positive integer p. The sequence is said to ...

  2. PAT 1085 Perfect Sequence

    PAT 1085 Perfect Sequence 题目: Given a sequence of positive integers and another positive integer p. ...

  3. PAT 1085 Perfect Sequence[难]

    1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. T ...

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

  5. PAT 1140 Look-and-say Sequence

    1140 Look-and-say Sequence (20 分)   Look-and-say sequence is a sequence of integers as the following ...

  6. PAT A1140 Look-and-say Sequence (20 分)——数学题

    Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D112213 ...

  7. PAT 甲级 1085 Perfect Sequence

    https://pintia.cn/problem-sets/994805342720868352/problems/994805381845336064 Given a sequence of po ...

  8. PAT 甲级 1051 Pop Sequence

    https://pintia.cn/problem-sets/994805342720868352/problems/994805427332562944 Given a stack which ca ...

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

随机推荐

  1. Mac 开发必备 利器 iterm2 oh-my-zsh

    推荐终端神器 iterm2 以及 oh-my-zsh,可以研究一下怎么用,好的开发环境是可以提高效率的,以及alias 的使用. https://www.zhihu.com/question/2744 ...

  2. 基于HTML5 Tab选项卡动画切换特效

    基于HTML5 Tab选项卡动画切换特效.这是一款基于HTML5+CSS3实现的带有动画切换效果的Tab选项卡插件cbpFWTabs.效果图如下: 在线预览   源码下载 实现的代码. html代码: ...

  3. 消息中间件系列四:RabbitMQ与Spring集成

    一.RabbitMQ与Spring集成  准备工作: 分别新建名为RabbitMQSpringProducer和RabbitMQSpringConsumer的maven web工程 在pom.xml文 ...

  4. VSCode之快捷键和常用插件

    前言 介绍一下我在VSCode中常用的一些快捷方式: ctrl+上下箭头 上下滚动页面 Ctrl+Shift+K 删除某一行 Alt+ ↑ / ↓ 移动某一行 Shift+Alt + ↓ / ↑ 复制 ...

  5. shell脚本学习笔记(符号)

    shell脚本的学习: 1.Shell的作用是解释运行用户的命令,用户输入一条命令,Shell就解释运行一条,这样的方式称为交互式(Interactive),Shell还有 一种运行命令的方式称为批处 ...

  6. 转:SQL Server 动态行转列

    http://www.cnblogs.com/gaizai/p/3753296.html http://www.cnblogs.com/maanshancss/archive/2013/03/13/2 ...

  7. 【中间件安全】IIS6安全加固规范

    1. 适用情况 适用于使用IIS6进行部署的Web网站. 2. 技能要求 熟悉IIS配置操作,能够利用IIS进行建站,并能针对站点使用IIS进行安全加固. 3. 前置条件 1. 根据站点开放端口.进程 ...

  8. 关于v$librarycache的几个字段含义

    对v$librarycache中的get,pin和reload的含义: Gets: (Parse) The number of lookups for objects of the namespace ...

  9. NB-Iot的应用领域、覆盖范围,是什么

    该部分分享的是物联网各垂直应用领域里,NB-IoT技术的部署,看看适合NB-IoT技术的垂直应用场景有哪些?垂直应用服务商又该如何部署? 1 NB-IoT适合的垂直应用场景有哪些? 2 NB-IoT垂 ...

  10. 读《javascript语法精粹》知识点总结

    昨天泡了大半天的读书馆,一口气看完了<javascript语法精粹>这本书,总体来说这本书还是写的不错,难怪那么多的推荐.<javascript语法精粹>主要是归纳与总结了ja ...