AcWing 3233. 火车购票(c++模拟)
原题链接
简单
作者:
ye_che
,
2021-06-21 20:00:35
,
所有人可见
,
阅读 375
#include<bits/stdc++.h>
using namespace std;
pair<int, int> seat[30];
int n, t;
int main()
{
for(int i = 1; i <= 20; i ++) seat[i] = {(i - 1) * 5 + 1, 5};
seat[21].second = 110;
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> t;
int k = 1;
while(seat[k].second < t) k ++;
if(k > 20)
{
k = 1;
while(t){
if(seat[k].second)
{
int u = min(t, seat[k].second);
seat[k].second -= u;
for(int j = seat[k].first; j < seat[k].first + u; j ++) cout << j << ' ';
seat[k].first += u;
t -= u;
}
k ++;
}
cout << endl;
continue;
}
seat[k].second -= t;
for(int j = seat[k].first; j < seat[k].first + t; j ++) cout << j << ' ';
seat[k].first += t;
cout << endl;
}
}