2021年-PTA模拟赛-L2-1 彩虹瓶(栈+模拟)

用栈模拟货架,测试点1不过的,不能不满足就马上break,必须输入完整

AcCode:

#include<iostream>
#include<stack>
using namespace std;
int main(){
    int N, M, K;
    cin >> N >> M >> K;
    while(K--){
        stack<int> s; //模拟货架
        int t = 0;
        bool flag = false;
        for(int i = 0; i < N; i++){
            int id;
            cin >> id;
            if(t + 1 == id){
                t++;
                while(!s.empty() && s.top() == t + 1){
                    t++;
                    s.pop();
                }
            }else{
                s.push(id);
                if(s.size() > M) flag = true;
            }
        }
        if(!s.empty() || flag) cout << "NO" << endl;
        else cout << "YES" << endl;
    }
    return 0;
}
posted @ 2025-03-15 00:40  Yuhhhhh  阅读(15)  评论(0)    收藏  举报