*浙大PAT甲级 1051
来源:互联网 发布:淘宝密码破解 编辑:程序博客网 时间:2024/05/01 03:18
判断序列是否能够通过大小为M的栈得来。
主要考察栈的模拟。
当栈为空时,或者栈顶不等于该值且栈的容量<M,那么就循环压入123......。
跳出循环如果栈顶不等于该值则是不合理,如果等于则弹出栈顶继续循环。
AC代码:
#include<iostream>#include<vector>#include<map>#include<cstdio>#include<algorithm>#include<queue>#include<cstring>#include<list>#include<set>#include<stack>#include<cmath>#define inf 26*26*26*10+5using namespace std;int a[1005];int main(){ int m,n,k; cin>>m>>n>>k; for(int i=0;i<k;i++) { for(int j=0;j<n;j++) { cin>>a[j]; } int d=1; int flag=0; stack<int> s; for(int z=0;z<n;z++) { while(s.empty()||(s.top()!=a[z]&&s.size()<m)) { s.push(d++); } if(s.top()!=a[z]) { cout<<"NO"<<endl; flag=1; break; } else { s.pop(); } } if(flag==0) cout<<"YES"<<endl; }}
0 0
- *浙大PAT甲级 1051
- 浙大pat甲级 1023
- 浙大pat甲级 1024
- 浙大pat甲级 1025
- 浙大PAT甲级 1026
- 浙大PAT甲级 1028
- 浙大PAT甲级 1029
- 浙大PAT甲级 1030
- 浙大PAT甲级 1031
- 浙大PAT甲级 1032
- 浙大PAT甲级 1033
- 浙大PAT甲级 1035
- 浙大PAT甲级 1037
- 浙大PAT甲级 1039
- 浙大PAT甲级 1040
- 浙大PAT甲级 1038
- 浙大PAT甲级 1041
- 浙大PAT甲级 1042
- 4.3 ipu_init_channel_buffer函数的详细分析
- spring xml classpath 路径设置
- JavaScript对象之数学函数运算-Math
- 锋利的JQuery 学习笔记
- java 基于网络编程的聊天小程序
- *浙大PAT甲级 1051
- jenkins参考网站
- 数据结构上机测试1:顺序表的应用
- Egret命令行手册
- HDU 4455 Substrings
- 王家林Spark视频
- bootstrap-chosen用法
- JNI: Java类中静态和非静态方法的区别
- 计算机科学领导者:卡内基梅隆大学ACL2016论文汇总