1. 程式人生 > >L2-032 彩虹瓶

L2-032 彩虹瓶

++ 題解 out 傳送門 應用 mes 棧的應用 namespace using

題目傳送門: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 彩虹瓶