1014 Waiting in Line (30 point(s))

本文介绍了一个银行排队系统的模拟算法,通过优先级队列实现客户在多个窗口间的最优分配,确保每位顾客选择等待时间最短的队伍。考虑到银行每天17:00关门,对于无法在关门前进店的顾客,系统会输出'Sorry'。文章提供了完整的C++代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题解

说是编程题,但是感觉就是一道英语题。看题仔细点就简单了。。。

Each customer will choose the shortest line to wait in when crossing the yellow line. 

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.  (this  does not include the person being served

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXN = 1010;
const int MAXM = 21;
struct node {
	int window;
	int start;
	int finish;
	bool operator < (const node& rhs) const {
		return rhs.finish == finish ? window > rhs.window : finish > rhs.finish; 
	}
}cus[MAXN];
int t[MAXN], winLast[MAXM];
int n, m, k, q;
int main() {
	scanf("%d%d%d%d", &n, &m, &k, &q);
	for(int i = 1; i <= k; ++i) scanf("%d", &t[i]);
	int cnt = 0;
	priority_queue<node> p;
	for(int i = 1; i <= m && cnt < k; ++i) {
		for(int j = 1; j <= n && cnt < k; ++j) {
			++cnt; // 
			cus[cnt].window = j;
			cus[cnt].start = winLast[j];
			cus[cnt].finish = winLast[j] = cus[cnt].start + t[cnt];
			p.push(cus[cnt]);
		}
	}
	for(int i = cnt + 1; i <= k; ++i) {
		node u = p.top(); p.pop();
		int win = u.window;
		cus[i].window = win;
		cus[i].start = winLast[win];
		cus[i].finish = winLast[win] = cus[i].start + t[i];
		p.push(cus[i]);
	}
	for(int i = 0; i < q; ++i) {
		int query;
		scanf("%d", &query);
		node u = cus[query];
		if(u.start >= (17 - 8) * 60) printf("Sorry\n");
		else printf("%02d:%02d\n", u.finish / 60 + 8, u.finish % 60); 
	}
	return 0;
} 

 

Traceback (most recent call last): File "train.py", line 620, in <module> main(opt) File "train.py", line 517, in main train(opt.hyp, opt, device, callbacks) File "train.py", line 119, in train csd = ckpt['model'].float().state_dict() # checkpoint state_dict as FP32 File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 692, in float return self._apply(lambda t: t.float() if t.is_floating_point() else t) File "/usr/src/app/models/yolo.py", line 239, in _apply self = super()._apply(fn) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 530, in _apply module._apply(fn) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 530, in _apply module._apply(fn) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 530, in _apply module._apply(fn) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 552, in _apply param_applied = fn(param) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 692, in <lambda> return self._apply(lambda t: t.float() if t.is_floating_point() else t) RuntimeError: CUDA error: no kernel image is available for execution on the device CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect. For debugging consider passing CUDA_LAUNCH_BLOCKING=1. wandb: Waiting for W&B process to finish, PID 448... (failed 1). wandb: You can sync this run to the cloud by running: wandb: wandb sync /usr/src/app/wandb/offline-run-20250312_065157-2p64ak4o wandb: Find logs at: ./wandb/offline-run-20250312_065157-2p64ak4o/logs/debug.log wandb: 运行train.py报错如上所示,如何解决
03-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值