A1051 Pop Sequence [栈的应用]

在这里插入图片描述

#include<vector>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<set>
#include<map>
#include<cstring>
#include<string>
#include<queue>
#include<array>
#include<stack>
using namespace std;
int arr[1001];
stack<int>st;
int main()
{
	int m, n, T;
	cin >> m >> n >> T;
	while (T--)
	{
		while (!st.empty())
		{
			st.pop();
		}
		for (int i = 0; i < n; i++)
		{
			cin >> arr[i];
		}
		int index = 0;
		bool flag = true;
		for (int i = 0; i < n; i++)
		{
			st.push(i + 1);
			if (st.size() > m)
			{
				flag = false;
				break;
			}
			while (!st.empty() && st.top() == arr[index])
			{
				st.pop();
				index++;
			}
		}
		if (st.empty())
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

posted @ 2020-07-20 15:13  _Hsiung  阅读(57)  评论(0编辑  收藏  举报