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 ...
随机推荐
- netstat实现原理
因为最近接手的项目是基于嵌入式Linux openwrt的,一开始以为会跟之前的服务器开发没什么大的区别,但是遇到问题去分析的时候才发现,工具链还是有些差别的,openwrt的netstat是属于一个 ...
- idea checkout 项目
1. 2.添加一个连接 选择远程目录checkout , 然后选择本地目录 但是这样会创建一个新的projectwindow 如果要创建为module的话 1.手动引入从svn check的 ...
- Groovy 和 Gradle
0.Groovy和Gradle是什么关系? Gradle,自动化构建工具,通过简单编写Groovy脚本,便可进行依赖管理并完成项目构建: 1. Groovy有什么用? 脚本+Java代码: 2. Gr ...
- 第四百一十六节,Tensorflow简介与安装
第四百一十六节,Tensorflow简介与安装 TensorFlow是什么 Tensorflow是一个Google开发的第二代机器学习系统,克服了第一代系统DistBelief仅能开发神经网络算法.难 ...
- php -- new self() 和 new static
看一段摘自网上的代码 class A { public static function get_self() { return new self(); } public static function ...
- AES和RSA加解密的Python用法
AES AES 是一种对称加密算法,用key对一段text加密,则用同一个key对密文解密, from Crypto import Random from Crypto.Hash import SHA ...
- python列表的切片操作允许索引超出范围
其余的不说,列表切片操作允许索引超出范围:
- Linux 访问权限
[TOC] Linux访问权限 Linux用户和用户组 查看当前用户用命令who am i 用命令id username可以显示指定用户的用户id.用户组id(GID).和所属附加群组的信息. 所有的 ...
- OpenGL矩阵变换,坐标空间变换
- Scala 按名称参数调用函数 与 =>的用法
转自:http://blog.csdn.net/shenxiaoming77/article/details/54835679 通常情况下,函数的参数是传值参数:即参数的值在它被传递给函数之前被确定. ...