AcWing 3233. 火车购票
原题链接
简单
# include<iostream>
# include<cstring>
# include<algorithm>
using namespace std;
int n;
int a[25][10];
int findempty(int i, int j){
int res = 1;
j++;
while(a[i][j]==0 && j%5!=0){
res++;
j++;
}
return res;
}
int main(){
cin>>n;
while (n--){
int flag = 0;
int x;
cin>>x;
for (int i = 0; i<20 ; i++){
for (int j = 0; j<5; j++){
if (a[i][j]==1) continue;
int y = findempty(i,j);
if (y>=x) {
flag = 1;
for (int k = 0; k<x; k++){
a[i][j+k]=1;
cout<<5*i+(j+k)+1<<" ";
}
cout<<endl;
goto breakloop;
}
}
}
breakloop: if (!flag){
int temp = x;
for (int i = 0; i<20; i++){
for (int j = 0; j<5; j++){
if (a[i][j]==0){
if (temp){
cout<<5*i+j+1<<" ";
a[i][j]=1;
temp--;
}
}
}
}
cout<<endl;
}
}
return 0;
}