只用了二维数组和结构体,暴力循环做法,做了两天,太不容易了打个🦶县
#include<iostream>
using namespace std;
struct person
{
int time;
int number;
};
int main() {
int n, m, k, q, time[2003], ask[2003] = { 0 }, now = 8 * 60, end = 17 * 60, finish[2100], h = 1, finish_i = 0, u = 0;
cin >> n >> m >> k >> q;
for (int i = 0; i < 2003; i++)time[i] = -1;
for (int i = 0; i < 2100; i++)finish[i] = -1;
for (int i = 0; i < k; i++)
{
cin >> time[i];
}
for (int i = 0; i < q; i++)
{
cin >> ask[i];
ask[i] --;
}
person a[42][22] = { 0 };
for (int i = 0; i < 12; i++)
{
for (int j = 0; j < n; j++)
{
a[i][j].number = h;
h++;
}
}
int t = 0;
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
a[i][j].time = time[t];
t++;
}
}
int tmin = a[0][0].time, tend[2100] = { 0 };
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)if (tmin > a[0][j].time && a[0][j].time > 0)tmin = a[0][j].time;
int f = 0;
for (int s = 0; s < n; s++)
{
if (a[0][s].time >= tmin) {
i--;
if (f == 0) {
now += tmin;
f = 1;
}
if (a[0][s].time == tmin)
{
finish[finish_i] = a[0][s].number - 1;
finish_i++;
tend[u] = now;
u++;
}
a[0][s].time -= tmin;
if (a[0][s].time == 0 && a[1][s].time != -1)
{
for (int o = 1; o < m; o++)a[o - 1][s] = a[o][s];
a[m - 1][s].time = time[t];
a[m - 1][s].number = t + 1;
t++;
}
}
}
tmin = 540;
}
for (int i = 0; i < q; i++)
{
for (int j = 0;j < k;j++) {
if (ask[i] == finish[j])
{
if (tend[j]-time[j] >= end)cout << "Sorry" << endl;else printf("%02d:%02d\n", tend[j] / 60, tend[j] % 60);
}
}
}
return 0;
}