AcWing 3233. 火车购票
原题链接
简单
作者:
把这题Ac了
,
2024-11-28 18:52:00
,
所有人可见
,
阅读 2
#include <iostream>
using namespace std;
const int N = 1010;
int te[N][N];
bool st[N][N];
int remains[N];
int n;
void add_flag(int i,int x){
int j = 1;
while(j <= 5 && st[i][j]) j++;
for(int k = 0;k < x;k++){
cout << te[i][j] << ' ';
st[i][j++] = 1;
}
}
int main(){
for(int i = 1;i <= 20;i++)
for(int j = 1;j <= 5;j++)
te[i][j] = (i - 1) * 5 + j;
for(int i = 1;i <= 20;i++) remains[i] = 5;
cin >> n;
for(int k = 0;k < n;k++){
if(k) cout << endl;
int nums;
cin >> nums;
int flag = 0;
for(int i = 1;i <= 20;i++){
if(remains[i] >= nums){
flag = 1;
remains[i] -= nums;
add_flag(i,nums);
nums = 0;
}
if(flag) break;
}
if(!flag){
for(int i = 1;i <= 20 && nums;i++){
if(nums >= remains[i]){
nums -= remains[i];
add_flag(i,remains[i]);
remains[i] = 0;
}else{
remains[i] -= nums;
add_flag(i,nums);
nums = 0;
}
}
}
}
return 0;
}