简单题。

#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[+];
stack<int>S; bool check()
{
while(!S.empty()) S.pop();
int Max=,sz=;
int now=;
int p=;
while()
{
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+||sz==tmp) break;
}
if(Max<=m&&now==k+) return ;
return ;
} int main()
{
scanf("%d%d%d",&m,&k,&n);
for(int i=;i<=n;i++)
{
for(int j=;j<=k;j++) scanf("%d",&a[j]);
if(check()) printf("YES\n");
else printf("NO\n");
} return ;
}

PAT (Advanced Level) 1051. Pop Sequence (25)的更多相关文章

  1. 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 ...

  2. 【PAT甲级】1051 Pop Sequence (25 分)(栈的模拟)

    题意: 输入三个正整数M,N,K(<=1000),分别代表栈的容量,序列长度和输入序列的组数.接着输入K组出栈序列,输出是否可能以该序列的顺序出栈.数字1~N按照顺序随机入栈(入栈时机随机,未知 ...

  3. PAT (Advanced Level) 1085. Perfect Sequence (25)

    可以用双指针(尺取法),也可以枚举起点,二分终点. #include<cstdio> #include<cstring> #include<cmath> #incl ...

  4. PAT 甲级 1051 Pop Sequence (25 分)(模拟栈,较简单)

    1051 Pop Sequence (25 分)   Given a stack which can keep M numbers at most. Push N numbers in the ord ...

  5. PAT 1051 Pop Sequence (25 分)

    返回 1051 Pop Sequence (25 分)   Given a stack which can keep M numbers at most. Push N numbers in the ...

  6. PAT Advanced 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 ...

  7. 【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 ...

  8. 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 ...

  9. 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 p ...

随机推荐

  1. 如何更改mysql可执行路径及更改mysql数据库文件路径

    一.如何更改服务中MySQL的可执行文件路径: 解决方法:到注册表里HKEY_LOCAL_MECHINE---SYSTEM ---CurrentControlSet 更改查找一. MySQL项值,然后 ...

  2. C#未将对象引用设置到对象的实例

    未将对象引用设置到对象的实例,这个错误的意思是对象为null,但你还要去取里面的值,所以计算机就不干了.解决办法一般是:用一个你不能确定是不是为null的对象时,尽量做个判断.if(object!=n ...

  3. 第四十三节,文件、文件夹、压缩包、处理模块shutil

    文件.文件夹.压缩包.处理模块shutil 文件处理 copyfileobj()模块函数 功能:将a文件的内容,复制到b文件中[有参] 使用方法:模块名称.copyfileobj(poen(" ...

  4. hdu_1495_非常可乐(bfs模拟)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1495 题意:不解释 题解:BFS模拟,不过要细心,把所有情况都列举出来,开一个数组记录状态,代码有点长 ...

  5. Java编译成功,用java 运行class时出现错误解决方法

    java -classpath class file's address; filename

  6. android网络编程之HttpUrlConnection的讲解--上传大文件

    1.服务器后台使用Servlet开发,这里不再介绍. 2.网络开发不要忘记在配置文件中添加访问网络的权限 <uses-permission android:name="android. ...

  7. golang vs java

    http://programmers.stackexchange.com/questions/83780/how-fast-can-go-go In terms of language design, ...

  8. Mysql:输出到文件

    mysql>tee /home/a.txt mysql>show processlist; mysql>exit tee命令能重定向输出,同时屏幕会同步显示.

  9. 命名空间“Microsoft”中不存在类型或命名空间名称“Office”(是缺少程序集引用吗?)

    通过引用这个解决,不同的的office版本,中间的版本号可能不同,如图所示:

  10. phpStorm设置显示代码行号

    File->Settings