PAT 1051
来源:互联网 发布:js获取li的class属性 编辑:程序博客网 时间:2024/05/01 01:27
PAT 1051
输入
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 2
输出
YESNONOYESNO
#include <cstdio>#include <iostream>#include <algorithm>#include <cmath>#include <vector>#include <stack>#include <queue>using namespace std;int main(){ int m,n,k; scanf("%d %d %d",&m,&n,&k); for(int i=0;i<k;i++) { bool flag = false; stack<int> s; queue<int> q; for(int j=1;j<=n;j++) { int temp; scanf("%d",&temp); q.push(temp); } for(int j=1;j<=n;j++) { s.push(j); if(s.size() >m ) { break; } while( !s.empty()&& !q.empty() && s.top() == q.front() ) { s.pop(); q.pop(); } } if(s.empty() && q.empty()) { printf("YES\n"); } else { printf("NO\n"); } } return 0;}
改用cin和cout,用时更短,前面是9ms,现在是0ms,内存方面有少量增加,前面是384KB,后面是412KB。
#include <cstdio>#include <iostream>#include <algorithm>#include <cmath>#include <queue>#include <stack>using namespace std;int main(){ int n,m,k; cin>>n>>m>>k; for(int i=0;i<k;i++) { stack<int> s; queue<int> q; for(int j=1;j<=m;j++) { int temp; cin>>temp; q.push(temp); } for(int j=1;j<=m;j++) { s.push(j); if(s.size()>n) { break; } while(!s.empty() && !q.empty() && s.top()==q.front() ) { s.pop(); q.pop(); } } if( s.empty() && q.empty() ) { cout<<"YES"<<endl; } else { cout<<"NO"<<endl; } } return 0;}
阅读全文
0 0
- pat 1051
- pat 1051
- pat 1051
- PAT 1051
- PAT 1051
- pat 1051 pop sequence
- PAT 1051-1060 题解
- pat advanced 1051
- PAT Advanced Level 1051
- PAT(甲级)1051
- 浙大PAT 1051
- *浙大PAT甲级 1051
- PAT乙级1051
- pat-bl-1051
- PAT甲级1051
- pat乙级 1051-1055
- PAT A 1051
- PAT 1051 pop Sequence
- python所有的标准异常类
- [LeetCode] Longest Common Prefix
- Android性能测试Monkey+Python
- HDU 6000 Wash【优先队列优化贪心】【最大值+最小值】
- Java transient
- PAT 1051
- 详解大端模式和小端模式
- Vagrant安装和使用
- JVM (完美图解)--1.6,1.7,1.8
- python如何实现批量注释print
- 【C++】关于C++中的友元函数的总结
- mybatis mysql 关于调用存储过程获取查询结果
- 关于java和java-version正常运行,javac提示不是内部或外部命令的解决方法
- 小程序微商城源码下载,微信小程序商城系统源代码下载