2020.10.08天梯赛练习

题目:彩虹瓶 

思路:

这个题就是考验你的作 “栈” 能力(手动滑稽),这个就是没有能拿的就放栈,能拿的就出栈,注意一下容积就可。

解题

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <stack>
using namespace std;
const long long N = 1e10 + 7;
const int maxn = 2e5 + 5;
const long long INF = 8e18;
typedef long long ll;
#define for0(i,n) for(int i = 0;i < n;i++)
#define for1(i,n) for(int i = 1;i <= n;i++)

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    while(k--){
        stack<int> s;
        int t = 1, x;
        int flag = 1;
        for(int i = 1; i <= n; i++){
            cin >> x;
            s.push(x);
            if(s.size() > m + 1)
                flag = 0;
            while(!s.empty() && s.top() == t){
                t++;
                s.pop();
             }
        }
        if(s.size() == 0 && flag)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}

 

posted @ 2020-11-15 19:23  emhhbw==  阅读(78)  评论(0)    收藏  举报