pat 1051Pop Sequence
模拟栈的过程,一开始我是用的cin来判断每行的每一个数字,然后判断回车结束。有一个点会超时,答案用数组先记录序列的方法非常好。有一个注意点就是访问s.top()的时候先要保证s。size()>0,这点和数组是一样的。
#include<bits/stdc++.h>
using namespace std;
int m,n,k;
int arr[];
int main()
{
stack<int>st;
scanf("%d %d %d", &m, &n, &k);
int i;
while (k--)
{
bool flag = true;
int current = ;
for (i = ; i <= n; i++)
{
scanf("%d", &arr[i]);
}
while (!st.empty())
{
st.pop();
}
for (i = ;i<=n; i++)
{
st.push(i);
if (st.size()>m)
{
flag = false;
break;
}
while (current <= n&&st.size()>&&st.top() == arr[current])
{
st.pop();
current++;
}
}
if (st.size() == && flag == true)
{
printf("YES\n");
}
else
printf("NO\n");
}
}
pat 1051Pop Sequence的更多相关文章
- PAT Perfect Sequence (25)
题目描写叙述 Given a sequence of positive integers and another positive integer p. The sequence is said to ...
- PAT 1085 Perfect Sequence
PAT 1085 Perfect Sequence 题目: Given a sequence of positive integers and another positive integer p. ...
- PAT 1085 Perfect Sequence[难]
1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. T ...
- 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 ...
- PAT 1140 Look-and-say Sequence
1140 Look-and-say Sequence (20 分) Look-and-say sequence is a sequence of integers as the following ...
- PAT A1140 Look-and-say Sequence (20 分)——数学题
Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D112213 ...
- PAT 甲级 1085 Perfect Sequence
https://pintia.cn/problem-sets/994805342720868352/problems/994805381845336064 Given a sequence of po ...
- PAT 甲级 1051 Pop Sequence
https://pintia.cn/problem-sets/994805342720868352/problems/994805427332562944 Given a stack which ca ...
- 【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 ...
随机推荐
- Unity读Excel 输出PC端(Windows)后不能读取的问题
问题:在Unity中用ExcelDataReader读Excel时,在编辑器模式下可以正常读取,但是在导出PC端app后读Excel却会报空,Excel读取失败. 要点: 1.把库文件Excel.dl ...
- 快速入门 WePY 小程序【转】
一.WePY介绍 WePY 是 腾讯 参考了Vue 等框架对原生小程序进行再次封装的框架,更贴近于 MVVM 架构模式, 并支持ES6/7的一些新特性. 二.WePY 使用 1.WePY的安装或更新都 ...
- android9.0适配HTTPS:not permitted by network security policy'
app功能接口正常,其他手机运行OK,但是在Android9.0的手机上报错 CLEARTEXT communication to 192.168.1.xx not permitted by netw ...
- 加速Windows 2003关机速度的设置方法
indows 2003是目前版本最高的Windows操作系统,虽然其功能比历史上任何一个版都要强,但是其关机操作却给大家带来了一些小麻烦.其实我们完全可以解除这些麻烦,让关机加速 一.关闭关机事件 ...
- 深入理解String类详解
1.Stringstr = "eee" 和String str = new String("eee")的区别 先看一小段代码, 1 public static ...
- 【中间件安全】IIS6安全加固规范
1. 适用情况 适用于使用IIS6进行部署的Web网站. 2. 技能要求 熟悉IIS配置操作,能够利用IIS进行建站,并能针对站点使用IIS进行安全加固. 3. 前置条件 1. 根据站点开放端口.进程 ...
- 理解面向过程(OPP)、面向对象(OOP)、面向切面(AOP)
概念 面向过程编程OPP:Procedure Oriented Programming,是一种以事物为中心的编程思想.主要关注“怎么做”,即完成任务的具体细节. 面向对象编程OOP:Object Or ...
- nuxt二级路由
耗费了大半天的时间,终于把页面的二级路由配置好了 先看我的目录 如果没有登陆页,根本就不用考虑嵌套路由的问题,主要的menu跳转和<nuxt />可以直接写到layouts/default ...
- python pytest测试框架介绍五---日志实时输出
同样的,在使用pytest进行自动化测试时,需要将实时日志打印出来,而不是跑完后才在报告中出结果. 不过,好在pytest在3.3版本开始,就支持这一功能了,而不用再像nose一样,再去装第三方插件. ...
- markdown 基本语法(转载)
最近感觉一直使用富文本编辑器写东西,感觉有点烦,所以就试着学习了一下简单的markdown编辑器的使用 原文地址:http://www.jianshu.com/p/815788f4b01d markd ...