-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path201609-2.cpp
More file actions
85 lines (80 loc) · 1.06 KB
/
201609-2.cpp
File metadata and controls
85 lines (80 loc) · 1.06 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include<iostream>
#include<cmath>
using namespace std;
int a[21][7];
int main()
{
int n,buy[101];
for(int i=0;i<20;i++)
{
for(int j=0;j<5;j++)
{
a[i][j]=0;
}
a[i][5]=5;
}
cin>>n;
for(int i=0;i<n;i++)
cin>>buy[i];
for(int tip=0;tip<n;tip++)
{
int order=buy[tip];
int line=0;
int pos=-1;
while(line!=20)
{
if(a[line][5]>=order)
{
pos=line;
break;
}
line++;
}
if(pos==-1)
{
for(int i=0;i<20;i++)
{
for(int j=0;j<5;j++)
{
if(a[i][j]==0&&order>0)
{
a[i][j]=1;
a[i][5]--;
order--;
cout<<5*i+j+1<<" ";
}
}
}
}
else
{
int num=0;
int t=0;
a[pos][5]-=order;
for(int i=0;i<5;i++)
{
if(a[pos][i]==0)
{
num++;
if(num==order)
{
t=i;
break;
}
}
else
{
num=0;
}
}
t=t-order+1;
for(int i=0;i<order;i++)
{
a[pos][t+i]=1;
cout<<5*pos+t+i+1<<" ";
}
}
cout<<endl;
}
return 0;
}