pat 1051Pop Sequence
模拟栈的过程,一开始我是用的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的更多相关文章
- PAT Perfect Sequence (25)
题目描写叙述 Given a sequence of positive integers and another positive integer p. The sequence is said to ...
- PAT 1085 Perfect Sequence
PAT 1085 Perfect Sequence 题目: Given a sequence of positive integers and another positive integer p. ...
- PAT 1085 Perfect Sequence[难]
1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. T ...
- 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 ...
- PAT 1140 Look-and-say Sequence
1140 Look-and-say Sequence (20 分) Look-and-say sequence is a sequence of integers as the following ...
- 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 ...
- PAT 甲级 1085 Perfect Sequence
https://pintia.cn/problem-sets/994805342720868352/problems/994805381845336064 Given a sequence of po ...
- PAT 甲级 1051 Pop Sequence
https://pintia.cn/problem-sets/994805342720868352/problems/994805427332562944 Given a stack which ca ...
- 【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 ...
随机推荐
- 力导向图Demo
<html> <head> <meta charset="utf-8"> <title>力导向图</title> < ...
- MySQL 下载地址获取
http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.26-winx64.msi 首先安装 mysql installer 安装器进行安装,之前会让你选 ...
- OSPF进程号的意义及多进程OSPF
OSPF进程号的意义及多进程OSPF—吴锦霖分享 1. OSPF进程号的概念 在配置OSPF时,我们采用的是router ospf命令,在该命令后面需要加上这个OSPF进程的进程号(Proces ...
- SAP PA Document List
RE-Real Estate 房地产 RE010-EN-Col95-Real Estate Processes in SAP ERP RE200-EN-Col95-Real Estate Manage ...
- python一个简单的websocket测试客户端
朋友发的,之前在网上一直没找着,先记着 #!/usr/bin/env python import asyncio import websockets import json async def tes ...
- windows下自动删除过期文件的脚本
windows下自动删除过期文件的脚本 前言: 比如日志文件每天都产生,时间长了就会有很大的一堆垃圾.整理一下 定时删除文件的方法. 正文: Windows: 定时删除tomcat日志和缓存.可以保留 ...
- OEL的下载
https://edelivery.oracle.com 注意的是:第一次下载安装的时候需要首先安装installer.exe软件,然后再下载即可.
- 通过User-agent进行SQL注入
声明:本文由Bypass整理并翻译,仅用于安全研究和学习之用. 文章来源:https://hackerone.com/reports/297478 我发现了一个SQL注入漏洞 /dashboard/d ...
- 【Static Program Analysis - Chapter 3】Type Analysis
类型分析,个人理解就是(通过静态分析技术)分析出代码中,哪些地方只能是某种或某几种数据类型,这是一种约束. 例如,给定一个程序: 其中,我们可以很直接地得到一些约束: 最后,经过简化可以得到: 对 ...
- express中间件--Morgan 日志记录
Morgan是一个node.js关于http请求的日志中间件 安装模块 npm install morgan --save #保存到package.json的依赖列表1使用方法 在终端打印日志...v ...