模拟栈的过程,一开始我是用的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. 阿里云ECS服务器无法上传文件的解决方案

    1.安装软件启动FTP服务 yum install vsftpd # 安装service vsftpd start # 启动服务chkconfig vsftpd on # 开机启动 2.防火墙ipta ...

  2. Ubuntu 16.04 ROS环境配置

    最近新入职一家公司,是搞智能无人驾驶的,用的操作系统是Ubuntu和ros,之前没接触过ros系统,既然公司用那就必须的学习啊,话不多说先装它一个ros玩玩... 1. Ubuntu 安装 ROS K ...

  3. Goland常用快捷键

    文件相关快捷键: CTRL+E,打开最近浏览过的文件. CTRL+SHIFT+E,打开最近更改的文件. CTRL+N,可以快速打开struct结构体. CTRL+SHIFT+N,可以快速打开文件. 代 ...

  4. Unity长连接

    http://blog.csdn.net/claine/article/details/52374546

  5. 阿里云负载均衡SLB 七层https协议 nginx 获取真实IP

    https://www.cnblogs.com/baylorqu/p/8565667.html https://help.aliyun.com/document_detail/54007.html

  6. JS设计模式——观察者模式(通俗易懂)

    Observer模式的概念 Observer模式是行为模式之一,它的作用是当一个对象的状态发生变化时,能够自动通知其他关联对象,自动刷新对象状态. Observer模式提供给关联对象一种同步通信的手段 ...

  7. win10下VS2017配置GSL库

    GSL库:GNU Scientific Library 1.  下载:下载Complete package, except sources和Sources两个exe文件 2.  安装:将两个exe安装 ...

  8. 【Py-Github】根据条件筛选Github repo的例子

    条件: language:python commits:>100 contributors:>2 stars:>5 fork:0 实现: from github import Git ...

  9. Go etcd初探

    1.etcd集群的配置 SET IP1_2380=http://127.0.0.1:2380 SET IP1_2379=http://127.0.0.1:2379 SET IP2_2380=http: ...

  10. MapReduce Map数 reduce数设置

    JobConf.setNumMapTasks(n)是有意义的,结合block size会具体影响到map任务的个数,详见FileInputFormat.getSplits源码.假设没有设置mapred ...