博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1051. Pop Sequence (25) 判断出栈序列是否合理
阅读量:4072 次
发布时间:2019-05-25

本文共 1495 字,大约阅读时间需要 4 分钟。

1051. Pop Sequence (25)

时间限制
100 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. For example, if M is 5 and N is 7, we can obtain 1, 2, 3, 4, 5, 6, 7 from the stack, but not 3, 2, 1, 7, 5, 6, 4.

Input Specification:

Each input file contains one test case. For each case, the first line contains 3 numbers (all no more than 1000): M (the maximum capacity of the stack), N (the length of push sequence), and K (the number of pop sequences to be checked). Then K lines follow, each contains a pop sequence of N numbers. All the numbers in a line are separated by a space.

Output Specification:

For each pop sequence, print in one line "YES" if it is indeed a possible pop sequence of the stack, or "NO" if not.

Sample Input:
5 7 51 2 3 4 5 6 73 2 1 7 5 6 47 6 5 4 3 2 15 6 4 3 7 2 11 7 6 5 4 3 2
Sample Output:
YESNONOYESNO
#include
#include
#include
#include
#include
#include
using namespace std;int main(){ int M,N,K,tem; scanf("%d %d %d",&M,&N,&K); for (int i=0; i
pushStaque,popStaQue; for (int j=1; j<=N;j++) { pushStaque.push(j);//进栈的队列 1234567 scanf("%d",&tem); popStaQue.push(tem); } stack
sta; while (true) { while ((sta.empty()||sta.top()!=popStaQue.front())&&!pushStaque.empty()&&!popStaQue.empty()&&sta.size()

转载地址:http://qmhji.baihongyu.com/

你可能感兴趣的文章
启动rabbitmq:ERROR: distribution port 25672 in use on localhost (by non-Erlang process?)
查看>>
Linux下mysql8.0用rpm安装
查看>>
linux下mysql 8.0忘记密码后重置密码
查看>>
mysql学习笔记(一)
查看>>
mysql学习笔记(二)
查看>>
mysql学习笔记(三)
查看>>
mysql学习笔记(四)
查看>>
mysql学习笔记(五)
查看>>
mysql学习笔记(六)
查看>>
iOS 微信SDK1.8.6后需要UniversalLink解决方案及采坑记录
查看>>
iOS 异形tabBar, 中间item凸起
查看>>
swift中单例的创建及销毁
查看>>
Swift中NSRange和Range的转换
查看>>
获取App Store中App的ipa包
查看>>
iOS 关于pods-frameworks.sh:permission denied报错的解决
查看>>
设置RGBColor
查看>>
设置tabbaritem的title的颜色及按钮图片
查看>>
动态设置label的高度
查看>>
获取键盘高度,调整输入框位置
查看>>
轮番图
查看>>