You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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;
}