PAT (Advanced Level) 1051. Pop Sequence (25)
简单题。
#include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> #include<string> #include<stack> #include<vector> using namespace std;int n,k,m; int a[1000+10]; stack<int>S;bool check() {while(!S.empty()) S.pop();int Max=0,sz=0;int now=1;int p=1;while(1){int tmp=sz;if(S.empty()&&p<=k){S.push(p++);sz++;Max=max(sz,Max);}else{if(S.top()==a[now]){S.pop(); now++;sz--;}else{if(p<=k){S.push(p++);sz++;Max=max(sz,Max);}}}if(now==k+1||sz==tmp) break;}if(Max<=m&&now==k+1) return 1;return 0; }int main() {scanf("%d%d%d",&m,&k,&n);for(int i=1;i<=n;i++){for(int j=1;j<=k;j++) scanf("%d",&a[j]);if(check()) printf("YES\n");else printf("NO\n");}return 0; }
转载于:https://www.cnblogs.com/zufezzt/p/5527624.html
PAT (Advanced Level) 1051. Pop Sequence (25)相关推荐
- 【PAT甲】1051 Pop Sequence (25分)判断出栈顺序的合法性
problem 1051 Pop Sequence (25分) Given a stack which can keep M numbers at most. Push N numbers in th ...
- 【PAT (Advanced Level) Practice】1051 Pop Sequence (25 分)
1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the order ...
- 【详细注释】1051 Pop Sequence (25 分)
立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Given a stack which can keep M numbers at most. Push N numbers in ...
- 【PAT甲级 stack queue的使用】1051 Pop Sequence (25 分) C++ 全部AC
题目 思路 维护三个集合:核心栈.数字队列.目标队列 详细思路见注释 题解 C++ #include<iostream> #include<stack> #include< ...
- PAT (Advanced Level) Practice 1166 Summit (25 分)
题目 因为只是判断是否是直接相连,所以觉得直接用暴力模拟,而且数据范围也很小.果然,许久不练题,A题的效率都下降了.不过,练题真的是打发时间的好途径. #include <bits/stdc++ ...
- PAT (Advanced Level) Practice 题解代码 - II (1051-1100)
PAT PAT (Advanced Level) Practice - II(1051-1100) -------------------------------------------------- ...
- PAT (Advanced Level) Practice 1043 Is It a Binary Search Tree (25 分) 凌宸1642
PAT (Advanced Level) Practice 1043 Is It a Binary Search Tree (25 分) 凌宸1642 题目描述: A Binary Search Tr ...
- PAT甲级1051 Pop Sequence:[C++题解]模拟栈、判断序列是否是合法的出栈序列
文章目录 题目分析 题目来源 题目分析 来源:acwing 分析: 题意:将1~N压栈,判断给定序列是否是合法的出栈序列. 对于序列1~N中的每个值i,先将其压入栈.然后对于它就有两种处理方法:要么压 ...
- PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642
PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642 题目描述: With the 2010 FIFA World Cu ...
最新文章
- 阿里将在雄安新区设3家子公司:涉AI、蚂蚁金服和菜鸟;北航设立全国首个人工智能专业,与百度合作办学...
- 搭建学习linux的系统环境准备
- matlab 小波分析实例,小波分析MATLAB实例
- java 进度条 百分比_java怎么让进度条带百分数
- 利用Bootstrap框架制作WordPress自适应主题
- CVPR2019/图像翻译:TransGaGa: Geometry-Aware Unsupervised Image-to-Image Translation几何感知的无监督图像到图像的翻译
- Linux编程起步 GCC基本用法
- devise安装使用指南
- 【金猿产品展】北森一体化人才管理云平台:让中国企业拥有世界领先的人才管理能力...
- JavaScript基本数据类型之String 和 Boolean
- 如何快速实现抖音分享与第三方登录?
- Enigma机密码加密解密的实现
- 页面生命周期:DOMContentLoaded,load,beforeunload,unload
- MySQL高阶教程索引
- PX4通过I2C方式添加自定义传感器(2)
- 公司要倒闭的6大征兆——集齐任意5个,兑换一次破产清算
- 60+精选网页UI设计作品PSD文件下载(上)
- 实习面试结束后的一些思考(已拿腾讯实习 offer)
- Powerpoint快捷键大全
- 【vue大师晋级之路第一集:Vue基础】第3章——模版语法
热门文章
- 微软正式发布PowerShell Core 6.0
- python3基础(九)内置函数
- nginx websocket 代理
- 7.生产者消费者 案例 (使用Lock 同步锁 方式,使用Condition完成线程之间的通信)...
- java-工具-轮子
- asp Eval()函数的一些使用总结
- OSPF NSSA 默认路由的问题
- autorun.inf删除方法
- 问题三十七:C++怎么解一元四次方程?(2)——怎么解一元三次方程
- 问题二十:C++全局debug “ray tracing图形”实例