PAT(甲级)1051
来源:互联网 发布:js null '' 编辑:程序博客网 时间:2024/04/30 23:01
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 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 2Sample Output:
YESNONOYESNO
#include <cstdio>#include <deque>using namespace std;deque <int> s;int main(){int M,N,K;scanf("%d%d%d",&M,&N,&K);int *date=new int[N];int i=0;//int j=1;while(K){bool flag = true;int j=1;s.clear();for(i=0;i<N;i++){ scanf("%d",&date[i]);for(;j<=date[i];j++){s.push_back(j);}if(s.size() >M||s.back() !=date[i]) flag=false;s.pop_back();}if(flag) printf("YES\n");else printf("NO\n");K--;}return 0;}
- PAT(甲级)1051
- *浙大PAT甲级 1051
- PAT甲级1051
- PAT 甲级
- PAT甲级 A1025.PAT RANKING
- PAT 甲级 1025 PAT Ranking
- PAT(甲级)1003
- PAT(甲级)1004
- PAT(甲级)1005
- PAT(甲级)1006
- PAT(甲级)1007
- PAT(甲级)1008
- PAT(甲级)1009
- PAT(甲级)1010
- PAT(甲级)1011
- PAT(甲级)1012
- PAT(甲级)1013
- PAT(甲级)1014
- miniet命令行(CLI)整理
- 数据缓冲区高速缓冲
- markdown_helloworld
- 图解Linux命令之--cat命令
- JavaScript高级程序设计之基本概念之数据类型第3.4讲笔记
- PAT(甲级)1051
- 看美国人竟然是这样教育小学生的
- 黑马程序员——Java语言基础知识(二)
- Android、IOS 图片上传接口(Java实现Servlet)。
- Android之复选框CheckBox使用
- HDOJ1495 非常可乐(bfs)
- PAT(甲级)1052
- 让source insight支持AT&T汇编语法高亮
- python如何生成exe