'commit'
This commit is contained in:
62
TangDou/XiTi/1348.cpp
Normal file
62
TangDou/XiTi/1348.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user