1494. 银行排队
priority_queue:优先队列
创建优先队列:
1)priority_queue<int> q;//数字大的优先级越大
2)priority_queue<int , vector<int> , less<int> >//数字大的优先级越大
3)priority_queue<int , vector<int> , greater<int>>//数字小的优先级越大
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int N=10010,M=110;
int n,m;
struct Person
{
int arrive_time;
int service_time;
bool operator< (const Person& t) const
{
return arrive_time < t.arrive_time;
};
} persons[N];
int main()
{
cin >> n >> m;
for(int i=0;i<n;i++)
{
int hour,minute,second,service_time;
scanf("%d:%d:%d %d",&hour,&minute,&second,&service_time);
service_time=min(service_time,60);
persons[i]={hour*3600 + minute*60+second,service_time*60};
}
priority_queue<int,vector<int>,greater<int>> windows;//定义存储int类型的数字小优先级高的队列
for(int i=0;i<m;i++) windows.push(8*3600);//m个窗口开窗时间为8点
sort(persons,persons+n);
int sum=0,cnt=0;
for(int i=0;i<n;i++)
{
auto person=persons[i];
int w=windows.top();//取出队头
windows.pop();//弹出窗口
if(person.arrive_time >17*3600) break;//时间超过17点结束循环
int start_time=max(person.arrive_time,w);
sum+=start_time-person.arrive_time;
cnt++;
windows.push(start_time+person.service_time);//办理完弹入窗口
}
printf("%.1lf\n",(double)sum/cnt/60);
return 0;
}