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

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int m,n,k;
  4. int arr[];
  5. int main()
  6. {
  7. stack<int>st;
  8. scanf("%d %d %d", &m, &n, &k);
  9. int i;
  10. while (k--)
  11. {
  12. bool flag = true;
  13. int current = ;
  14. for (i = ; i <= n; i++)
  15. {
  16. scanf("%d", &arr[i]);
  17. }
  18. while (!st.empty())
  19. {
  20. st.pop();
  21. }
  22. for (i = ;i<=n; i++)
  23. {
  24. st.push(i);
  25. if (st.size()>m)
  26. {
  27. flag = false;
  28. break;
  29. }
  30. while (current <= n&&st.size()>&&st.top() == arr[current])
  31. {
  32. st.pop();
  33. current++;
  34. }
  35. }
  36. if (st.size() == && flag == true)
  37. {
  38. printf("YES\n");
  39. }
  40. else
  41. printf("NO\n");
  42. }
  43. }

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. 力导向图Demo

    <html> <head> <meta charset="utf-8"> <title>力导向图</title> < ...

  2. MySQL 下载地址获取

    http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.26-winx64.msi 首先安装 mysql installer 安装器进行安装,之前会让你选 ...

  3. OSPF进程号的意义及多进程OSPF

    OSPF进程号的意义及多进程OSPF—吴锦霖分享    1. OSPF进程号的概念 在配置OSPF时,我们采用的是router ospf命令,在该命令后面需要加上这个OSPF进程的进程号(Proces ...

  4. SAP PA Document List

    RE-Real Estate 房地产 RE010-EN-Col95-Real Estate Processes in SAP ERP RE200-EN-Col95-Real Estate Manage ...

  5. python一个简单的websocket测试客户端

    朋友发的,之前在网上一直没找着,先记着 #!/usr/bin/env python import asyncio import websockets import json async def tes ...

  6. windows下自动删除过期文件的脚本

    windows下自动删除过期文件的脚本 前言: 比如日志文件每天都产生,时间长了就会有很大的一堆垃圾.整理一下 定时删除文件的方法. 正文: Windows: 定时删除tomcat日志和缓存.可以保留 ...

  7. OEL的下载

    https://edelivery.oracle.com 注意的是:第一次下载安装的时候需要首先安装installer.exe软件,然后再下载即可.

  8. 通过User-agent进行SQL注入

    声明:本文由Bypass整理并翻译,仅用于安全研究和学习之用. 文章来源:https://hackerone.com/reports/297478 我发现了一个SQL注入漏洞 /dashboard/d ...

  9. 【Static Program Analysis - Chapter 3】Type Analysis

    类型分析,个人理解就是(通过静态分析技术)分析出代码中,哪些地方只能是某种或某几种数据类型,这是一种约束.   例如,给定一个程序: 其中,我们可以很直接地得到一些约束: 最后,经过简化可以得到: 对 ...

  10. express中间件--Morgan 日志记录

    Morgan是一个node.js关于http请求的日志中间件 安装模块 npm install morgan --save #保存到package.json的依赖列表1使用方法 在终端打印日志...v ...