PAT1051. Pop Sequence (25)
#include <iostream>
#include <stack>
using namespace std;
int sizeMax,n,k;
stack<int> sta;
int queueNum;
int num;
int j;int flag=0;
int main(){
cin>>sizeMax>>n>>k;
while(k--){
while(!sta.empty()){sta.pop();}
queueNum=1;
flag=0;
for(int i=0;i<n;i++){
cin>>num;
if(flag){continue;}
if(num>queueNum){
for(j=queueNum;j<num;j++){
sta.push(j);
}
if(sta.size()>=sizeMax){
flag=1;
continue;
}
queueNum=num+1;
}else if(num<queueNum){
int top=sta.top();
if(top!=num){
flag=1;
continue;
}
sta.pop();
}else{
queueNum++;
}
}
if(flag){
cout<<"NO"<<endl;
}else{
cout<<"YES"<<endl;
}
}
return 0;
}
PAT1051. Pop Sequence (25)的更多相关文章
- 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 ...
- PAT1051:Pop Sequence
1051. Pop Sequence (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a ...
- pat02-线性结构4. Pop Sequence (25)
02-线性结构4. Pop Sequence (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- PTA 02-线性结构4 Pop Sequence (25分)
题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/665 5-3 Pop Sequence (25分) Given a stack wh ...
- PAT 甲级 1051 Pop Sequence (25 分)(模拟栈,较简单)
1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the ord ...
- PAT 1051 Pop Sequence (25 分)
返回 1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the ...
- 数据结构练习 02-线性结构3. Pop Sequence (25)
Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and p ...
- 1051. Pop Sequence (25)
题目如下: Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N ...
- 【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 ...
随机推荐
- JZOJ.5279【NOIP2017模拟8.15】香港记者
Description
- docker 中安装 FastDFS 总结
如题,参考各资料后,安装FastDFS总结.基于已有docker镜像 https://hub.docker.com/r/luhuiguo/fastdfs/ docker pull luhuiguo/f ...
- H5页面在微信中禁止下拉露出网页
H5页面在微信中禁止默认事件的执行,js添加代码 $(function () { /************微信h5页面禁止下拉露出网页来**************/ $('body').on('t ...
- cocos2d-X学习之主要类介绍:场景(CCScene)
场景(CCScene) 类结构: CCScene主要有以下两个函数: bool init () //初始化函数 static CCScene * node (void) //生CCScene 作为 ...
- HDU 3388 Coprime(容斥原理+二分)
Coprime Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- Java RTTI and Reflection
Reference: Java编程思想 java 反射(Reflect) Java系列笔记(2) - Java RTTI和反射机制 Java Reflection in Action, 有空再补 -- ...
- 3*0.1 == 0.3 将会返回什么?true 还是 false?
false,因为有些浮点数不能完全精确的表示出来 public static void main(String[] args) { System.out.println(3 * 0.1); Syste ...
- SpringMVC是单例的,高并发情况下,如何保证性能的?
首先在大家的思考中,肯定有影响的,你想想,单例顾名思义:一个个排队过... 高访问量的时候,你能想象服务器的压力了... 而且用户体验也不怎么好,等待太久~ 实质上这种理解是错误的,Java里有个A ...
- 【ORACLE】10步全然卸载CRS
版权声明:本文为博主原创文章(原文:blog.csdn.net/clark_xu 徐长亮的专栏),未经博主同意不得转载. https://blog.csdn.net/u011538954/articl ...
- sizeof 是编译时运算符
typedef char RT1;typedef struct{ char a[2]; } RT2;template<typename T> RT1 test(typename T::X ...