zoukankan      html  css  js  c++  java
  • 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;
    		}
    	}
    }
    
    
  • 相关阅读:
    深拷贝与浅拷贝
    图片旋转插件
    promise 小抄
    github fork项目更改后与原作者同步更新
    eslint 的配置
    css规范
    Object类
    BigIntager
    System类
    Math类和Random类
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13812030.html
Copyright © 2011-2022 走看看