首页 > 其他 > 详细

L2-032 彩虹瓶

时间:2019-04-04 11:52:37      阅读:203      评论:0      收藏:0      [点我收藏+]

题目传送门:https://pintia.cn/problem-sets/994805046380707840/problems/1111914599412858889

题解:

//本题主要是栈的应用
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;

int main() {
    int N, M, K, temp;
    cin >> N >> M >> K;
    stack<int>s1;
    while (K--) {
        while (!s1.empty()) {
            s1.pop();
        }
        int f = 1;
        bool flag = false;
        for (int i = 0; i < N; i++) {
            cin >> temp;
            if (temp == f) {
                f++;
                while (!s1.empty()&& s1.top() == f) {
                    s1.pop();
                    f++;
                }
            }
            else {
                s1.push(temp);
                if (s1.size() > M) {
                    flag = true;
                }
            }
        }
        if (flag||!s1.empty()) {
            cout << "NO" << endl;
        }
        else {
            cout << "YES" << endl;
        }
    }
    return 0;
}

 

L2-032 彩虹瓶

原文:https://www.cnblogs.com/Gzu_zb/p/10653912.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!