1051 Pop Sequence (25 point(s))

题解

stack简答模拟。

#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
using namespace std;
const int MAXN = 1010;
int t[MAXN];
int n, m, k, x;
int main() {
	scanf("%d%d%d", &m, &n, &k);
	for(int i = 0; i < k; ++i) {
		stack<int> s;
		queue<int> q;
		for(int j = 0; j < n; ++j) {
			scanf("%d", &x);
			q.push(x);
		}
		for(int j = 1; j <= n; ++j) {
			s.push(j);
			if(s.size() > m) break;
			while(!q.empty() && !s.empty() && s.top() == q.front()) {
				s.pop();
				q.pop();
			}
		}
		printf("%s\n", s.empty() ? "YES" : "NO");
	} 
	return 0;
}

 

相关文章:

  • 2021-09-11
  • 2021-12-12
  • 2021-09-11
  • 2021-09-30
  • 2021-09-22
  • 2020-03-13
  • 2021-09-29
  • 2018-06-27
猜你喜欢
  • 2021-09-30
  • 2021-09-29
  • 2021-10-14
  • 2018-05-11
  • 2018-10-12
  • 2021-09-29
  • 2021-09-11
  • 2019-11-17
相关资源
相似解决方案