Files
python/TangDou/XiTi/1348.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

63 lines
1.8 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
int main() {
//0:可以销售,-1已经销售
int a[100];
for (int i = 0; i < 100; i++) {
a[i] = 0;
}
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int p;
cin >> p;
//假设输入的是2那么就是从小到大找连续两个
//(1)从头遍历可能的座位
bool success = false;
for (int j = 0; j < 100; j++) {
if (a[j] == 0) {
bool can = true;
//向后找连续p个,注意是5个人一排~
for (int k = j + 1; k < j + p; k++) {
if (a[k] == -1 || (j % 10 <= 4 && k % 10 >= 5) ||
(j % 10 >= 5 && k % 10 <= 4)) {
can = false;
break;
}
}
if (can) {
a[j] = -1;
cout << j + 1 << " ";
for (int k = j + 1; k < j + p; k++) {
a[k] = -1;
cout << k + 1 << " ";
}
cout << endl;
success = true;
break;
}
}
}
if (!success) {
int count = 0;
//从小的开始插空
for (int j = 0; j < 100; j++) {
if (a[j] == 0) {
a[j] = -1;
cout << j + 1 << " ";
count++;
}
//如果达到个数
if (count == p) {
cout << endl;
break;
}
}
}
}
return 0;
}