L2-032 彩虹瓶

纯模拟,一次就AC了。

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
vector<int> huoja;//货架
queue<int> order;//发货顺序
int main() {
	int n, m, k;//颜色数量 货架容量 发货顺序
	cin >> n >> m >> k;
	while (k--) {
		huoja.clear();
		while (!order.empty()) order.pop();
		for (int i = 0; i < n; i++) {
			int color;
			cin >> color;
			order.push(color);
		}
		int i = 1;
		for (i = 1; i <= n; i++) {//想得到的颜色
			if (!huoja.empty()) {//非空
				if (huoja.back() == i) {
					huoja.pop_back();
					continue;
				}
	            //如果在货架上 但是不是最后一个
				if (find(huoja.begin(), huoja.end(), i) != huoja.end()) {
					cout << "NO" << '\n';
					break;
				}
			}
			int flag = 0;
			//货架上没有 去仓库找
			while (!order.empty()) {
				if (order.front() == i) {
					order.pop();
					break;//将颜色使用掉
				}
				else {
					//取出来放到货架上
					int color = order.front();
					order.pop();
					huoja.push_back(color);
				}
				if (huoja.size() > m) {
					flag = 1;
					cout << "NO" << '\n';
					break;
				}
			}
			if (flag) break;
		}
		if (i > n) {
			cout << "YES" << '\n';
		}
	}
	return 0;
}
posted @ 2024-03-20 12:27  YuKiCheng  阅读(19)  评论(0编辑  收藏  举报