模拟栈的过程,一开始我是用的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. java.lang.UnsatisfiedLinkError: No implementation found for long org.opencv.core.Mat.n_Mat()

    Android调试openCV4Android的时候出现以下错误 java.lang.UnsatisfiedLinkError: No implementation found for long or ...

  2. C#.net mysql There is already an open datareader associated with this command引发的问题

    [参考]There is already an open datareader associated with this command引发的问题 我在语句中并未使用 DataReader,未何也提示 ...

  3. Java开发工程师面试题1

    时间2019-1-2 地点上海 package service; import java.text.SimpleDateFormat; import java.util.Date; public cl ...

  4. 内建模块collections的使用

    # -*-coding:utf-8 -*- from collections import namedtuple Point=namedtuple('Point',['x','y']) p=Point ...

  5. Mixed Content: xxx This request has been blocked; the content must be served over HTTPS.

    在升级https的过程中,出现如下问题: Mixed Content: The page at 'https://www.xxx.com/denglu.html' was loaded over HT ...

  6. 高仿QQ、微信效果的图片浏览器(支持原图和缩略图、多种手势、CocoaPods)

    感谢原文作者的分享 本文转载至 http://my.oschina.net/u/2406027/blog/735738 PYPhotoBrowser GitHub地址:https://github.c ...

  7. 【面试题】java面试题整理(有空再贴答案)

    面试题+基础 各家的面试题其实都大同小异, 掌握基础和原理,走到哪都不怕. 基础 leetcode上有一些总结,star数非常高了.贴上url https://github.com/CyC2018/C ...

  8. How not to alienate your reviewers, aka writing a decent rebuttal?

    [forwarded from https://nebelwelt.net/blog/20180704-rebuttal.html] Assuming you have given everythin ...

  9. Springboot中enable注解

    这句话可以作为理解springboot自动注入的原理的钥匙:ImportSelector接口的selectImports返回的数组(类的全类名)都会被纳入到spring容器中. 至于spring怎么根 ...

  10. 怎么下载geventwebsocket

    pip install gevent-websocket sudo pip install gevent-websocket