测试点5:边界测试点。且要注意到达时间在17:00之前,但服务时间在17:00之后的客户依旧是有效客户!(算法笔记对这里的理解有错误)
测试点3/4:注意输出格式!你妈我想骂人了并且这么做了!气死我了!最后的结果并不是直接取天棚…使用普通的除法保留就可以了!!我为什么要多此一举!!我测试了好几个小时!!居然是这个原因!!气死我了
【思路:恶心的模拟题+优先队列】
网络上关于优先队列的版本已经有很多了,但我感觉我写的你们应该能看懂吧毕竟我太菜了。
简单来说,你把顾客按抵达时间排好序以后,将K个窗口想象成优先队列的最大尺寸。如果尺寸足够用,直接压栈(此时意味着顾客并不需要等待);如果尺寸不够用,弹栈,分两种情况:(a)弹出的时间比当前顾客的时间小,意味着这个顾客在当前顾客抵达之前就已经离开了,简单压栈即可;(b)弹出的时间比当前顾客的时间大,需要等待,处理好求和后,再压栈即可。
#include <bits/stdc++.h>
using namespace std;
struct node
{
int time,process;
};
node customer[10010];
bool cmp(node a,node b)
{
return a.time<b.time;
}
int main(void)
{
int N,K,tmp,sum=0;
int h,m,s;
priority_queue<int,vector<int>,greater<int> > q;
scanf("%d%d",&N,&K);
for(int i=0;i<N;i++)
{
scanf("%d:%d:%d %d",&h,&m,&s,&tmp);
customer[i].time=(h*60+m)*60+s;
customer[i].process=tmp*60;
}
sort(customer,customer+N,cmp);
for(int i=N-1;i>=0;i--)
if(customer[i].time>17*60*60) N--;
for(int i=0;i<K;i++) q.push(8*60*60);
for(int i=0;i<N;i++)
{
tmp=q.top();
q.pop();
if(tmp<=customer[i].time)
q.push(customer[i].time+customer[i].process);
else
{
sum+=tmp-customer[i].time;
q.push(tmp+customer[i].process);
}
}
printf("%.1f",sum/N/60.0);
}