-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path火车购票.cpp
67 lines (63 loc) · 1.7 KB
/
火车购票.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
const int maxn = 20;
struct Seat {
int emptyCount;//×î´óÁ¬Ðø×ùλÊý
int seat[5];
Seat() {
emptyCount = 5;
memset(seat, 0, 5 * sizeof(int));
}
};
int main() {
int n;
cin >> n;
vector<int> v(n);
for(int i = 0; i < n; i++)
cin >> v[i];
Seat seat[maxn];
for(int i = 0; i < n; i++) {
int need = v[i];
bool find = false;
for(int j = 0; j < maxn; j++) {
if(seat[j].emptyCount >= need){
int k = 0;
while(seat[j].seat[k]) k++;
for(int l = 0; l < need - 1; l++){
seat[j].seat[k] = 1;
cout << j * 5 + 1 + k << " ";
k++;
}
seat[j].seat[k] = 1;
cout << j * 5 + 1 + k << endl;
seat[j].emptyCount -= need;
find = true;
break;
}
}
if(!find){
vector<int> temp;
for(int j = 0; j < maxn; j++) {
if(need == 0)
break;
for(int k = 0; k < 5; k++){
if(need == 0)
break;
if(seat[j].seat[k] == 0){
seat[j].seat[k] = 1;
seat[j].emptyCount--;
need--;
temp.push_back(j * 5 + 1 + k);
}
}
}
int ff = 0;
for(; ff < temp.size() - 1; ff++)
cout << temp[ff] << " " ;
cout << temp[ff] << endl;
}
}
return 0;
}