1014
1 Key Points
Note that since the bank is closed everyday after 17:00, for those customers who cannot be served before 17:00, you must output “Sorry” instead.
如果不能在17:00之前开始服务,则输出“Sorry”
vector<int>
删除元素:vector<int>::iterator it
遍历至要删除的元素 + v.erase(it)
2 Answers
#include <cctype>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct custom {
int cost, finish;
} cu[1005];
vector<int> v[21];
int main() {
int n, m, k, q;
scanf("%d %d %d %d", &n, &m, &k, &q);
int i;
for (i = 0; i < k; i++) {
scanf("%d", &cu[i].cost);
}
for (i = 0; i < n && i < k; i++) {
cu[i].finish = cu[i].cost;
v[i].push_back(i);
}
for (; i < m * n && i < k; i++) {
cu[i].finish = cu[v[i % n][v[i % n].size() - 1]].finish + cu[i].cost;
v[i % n].push_back(i);
}
for (; i < k; i++) {
int mintime = cu[v[0][0]].finish, minnum = 0;
for (int j = 1; j < n; j++) {
if (cu[v[j][0]].finish < mintime) {
minnum = j;
mintime = cu[v[j][0]].finish;
}
}
cu[i].finish = cu[v[minnum][v[minnum].size() - 1]].finish + cu[i].cost;
vector<int>::iterator it = v[minnum].begin();
v[minnum].erase(it);
v[minnum].push_back(i);
}
for (i = 0; i < q; i++) {
int num;
scanf("%d", &num);
if (cu[num - 1].finish - cu[num - 1].cost < 540) {
// cout << num - 1 << " " << cu[num - 1].finish << endl;
int h = cu[num - 1].finish / 60 + 8;
int m = cu[num - 1].finish % 60;
printf("%02d:%02d\n", h, m);
}
else {
printf("Sorry\n");
}
}
return 0;
}
/*
Sample Input:
2 2 7 5
1 2 6 4 3 534 2
3 4 5 6 7
Sample Output:
08:07
08:06
08:10
17:00
Sorry
*/