1017 Queueing at Bank
Suppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow line, until it is his/her turn to be served and there is a window available. It is assumed that no window can be occupied by a single customer for more than 1 hour.
Now given the arriving time T and the processing time P of each customer, you are supposed to tell the average waiting time of all the customers.
Each input file contains one test case. For each case, the first line contains 2 numbers: N (≤104) - the total number of customers, and K (≤100) - the number of windows. Then N lines follow, each contains 2 times: HH:MM:SS - the arriving time, and P - the processing time in minutes of a customer. Here HH is in the range [00, 23], MM and SS are both in [00, 59]. It is assumed that no two customers arrives at the same time.
Notice that the bank opens from 08:00 to 17:00. Anyone arrives early will have to wait in line till 08:00, and anyone comes too late (at or after 17:00:01) will not be served nor counted into the average.
For each test case, print in one line the average waiting time of all the customers, in minutes and accurate up to 1 decimal place.
- 7 3
- 07:55:00 16
- 17:00:01 2
- 07:59:59 15
- 08:01:00 60
- 08:00:00 30
- 08:00:02 2
- 08:03:00 10
8.2
自己写的代码,基本思路都是没错的,但是有个问题是在求三个窗口最快的结束时间我用的是循环找到最快结束的窗口,但是不知道为什么就出现错误了,还是得多写写题目,提高自己得代码水平!
- #include
- #include
- #include
- using namespace std;
-
- typedef pair<int,int> PII;
- vector
v;//p表示当前机器使用者的开始时间和处理时间,s表示客户的信息 -
- int main(){
- int n,k,num=0,sum=0;
- cin >> n >> k;
- int q[k]={0},w[k]={0};//分别表示当前用户的开始时间和处理业务所需要的时间
-
- int t,h,m,s,r,T;
- for(int i=0;i
- scanf("%d:%d:%d %d",&h,&m,&s,&r);
- t=h*3600+m*60+s;//到达银行时间全部用秒来表示
- T=r*60;
- if(t>=17*60*60) continue;
- v.push_back({t,T});
- num++;
- }
-
- sort(v.begin(),v.end());
-
- int j;
- for(int i=0;i
- auto a=v[i].first,b=v[i].second;
- if(a<=8*3600){
- sum+=8*3600-a;
- a=8*3600;
- }
- int minn=1e9;
- for(j=0;j
- if(q[j]==0 || minn>q[j]+w[j]){
- minn=q[j]+w[j];//找到最快结束的机子
- }
- }
- q[j]=a,w[j]=b;
- cout << minn << endl;
- if(minn<=a) continue;//结束时间<=到达时间,无需等待,直接用
- sum+=minn-a;//前面有人再用着,等待时间
- }
- cout << sum << endl;
- //printf("%.1lf\n",((double)sum)/60/num);
-
- return 0;
- }
看看大佬的代码:
- #include
- #include
- #include
- using namespace std;
-
- const int N=10010;
- struct person{
- int come,time;
- }p[N];
- bool cmp(person a,person b){
- return a.come
- }
- int total=0;
- int main(){
- int n,k,cnt;
- scanf("%d%d",&n,&k);
- for(int i=1;i<=n;i++){
- int hh,ss,mm,tt;
- scanf("%d:%d:%d %d",&hh,&mm,&ss,&tt);
- int sum=hh*3600+mm*60+ss;
- if(sum>61200) continue;
- p[++cnt].time=tt*60;
- p[cnt].come=sum;
- }
- sort(p+1,p+1+cnt,cmp);
- priority_queue<int,vector<int>,greater<int>> q;
- for(int i=1;i<=k;i++) q.push(28800);
- for(int i=1;i<=cnt;i++){
- if(q.top()<=p[i].come){
- q.push(p[i].come+p[i].time);
- q.pop();
- }
- else{
- total+=q.top()-p[i].come;
- q.push(q.top()+p[i].time);
- q.pop();
- }
- }
- (!cnt)?printf("0.0\n"):printf("%.1lf",((double)total/60.0)/(double)cnt);
-
- return 0;
- }
好好学习,天天向上!
我要考研!
-
相关阅读:
CvT:微软提出结合CNN的ViT架构 | 2021 arxiv
Linux设置tomcat开机自启
Ansible自动化运维工具介绍与部署
Docker 基础命令操作
Revit中“结构框架显示与剪切“的应用和一键剪切功能
Qt6远程连接MySQL数据库(简单易上手版)
【SpringBoot】理解配置背后的 PropertySource 抽象
TDengine防火墙配置
【LIN总线测试】——LIN主节点网络管理测试
linux上mysql 8.0安装
-
原文地址:https://blog.csdn.net/weixin_50679551/article/details/126778313
-
最新文章
-
沪漂五周年了:我越来越迷茫了
Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
MySQL-Seconds_behind_master的精度误差
[MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
Agent OS :五种驯服不确定性的范式
PortSwigger SQL注入LAB11
数据库即时编译JIT
[Begin]AI Learn Data Day 0
深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU