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 ...
随机推荐
- mysql数据库导入到oracle数据库
首先,写一个cmd脚本 xx.cmd sqlldr username/password control=xx.ctl errors=10000000 direct=y 再写一个bat脚本xx.bat ...
- css3动画效果:1基础
css动画分两种:过渡效果transition .关键帧动画keyframes 一.过渡效果transition 需触发一个事件(如hover.click)时,才改变其css属性. 过渡效果通常在用户 ...
- 【微信】QQ邮箱助手不提醒解决
1.问题及原因: 微信上的QQ邮箱提醒功能失效了,收到信后不提醒.忘了是使用了TIM,还是使用了QQ邮箱之后才出现的. 不过原因是:QQ邮箱提醒被设置为仅在QQ邮箱客户端提醒 2.解决: 重新安装QQ ...
- libprotobuf 编译错误处理
1. 编译完链接的时候报错undefined reference to well_known_types_js' 出现这个错误的原因是升级gcc导致的,是程序依赖的include文件和实际链接的文件不 ...
- 3 CActiveXUI的一个Bug
如果主窗口直接用变量生成,则关闭窗口时会产生崩溃 如果用new的方式生成,则不会崩溃,所以给出一个临时的快速解决方案,即主窗口都用new生成,_tWinMain改为下面这样: i ...
- Spring Data 关于Repository的介绍(四)
Repository类的定义: public interface Repository<T, ID extends Serializable> { } 1)Repository是一个空接口 ...
- 2015-03-22——js常用其它方法
Function Function.prototype.method = function (name, func) { this.prototype[name] = func; //此时th ...
- 搜索过滤grep(win下为findstr)
搜索过滤grep(win下为findstr) 1.主要参数 [options]主要参数: -c:只输出匹配行的计数. -i:不区分大小写 -h:查询多文件时不显示文件名. -l:查询多文件时只输出包含 ...
- [NOIP2018TG]保卫王国
[NOIP2018TG]保卫王国 BZOJ luogu 当动态dp模板题写的,(全集-最大点权独立集)不能放军队的+inf,必须放军队-inf即可 注意矩阵乘法的顺序问题 #define ll lon ...
- Vue(1)- es6的语法、vue的基本语法、vue应用示例,vue基础语法
一.es6的语法 1.let与var的区别 ES6 新增了let命令,用来声明变量.它的用法类似于var(ES5),但是所声明的变量,只在let命令所在的代码块内有效.如下代码: { let a = ...