1014

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
*/

3 References

  1. pat1014. Waiting in Line (30) - Deribs4 - 博客园
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值