-
Notifications
You must be signed in to change notification settings - Fork 0
/
pat 1017.cpp
88 lines (85 loc) · 2.23 KB
/
pat 1017.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <cstring>
#include <queue>
#include <string>
using namespace std;
struct window
{
int h;
int m;
int s;
bool operator <(const window &a)const
{
if(a.h<h)
return true;
else if(a.h==h && a.m<m)
return true;
else if(a.h==h && a.m==m && a.s<s)
return true;
return false;
}
};
struct customer
{
int h;
int m;
int s;
int process;
bool operator <(const customer &a)const
{
if(a.h<h)
return true;
else if(a.h==h && a.m<m)
return true;
else if(a.h==h && a.m==m && a.s<s)
return true;
return false;
}
};
int main()
{
int N,K,i;
double wait=0;
window win={8,0,0};
customer cu;
priority_queue<window> W;
priority_queue<customer> C;
scanf("%d%d",&N,&K);
for(i=0;i<N;i++)
{
scanf("%d:%d:%d %d",&cu.h,&cu.m,&cu.s,&cu.process);
if(cu.h<17 || (cu.h==17 && cu.m==0 && cu.s==0))
C.push(cu);
}
N=C.size();
if(N == 0)
{
printf("0.0");
return 0;
}
for(i=0;i<K;i++)
W.push(win);
while(!C.empty())
{
win=W.top();
W.pop();
cu=C.top();
C.pop();
if(cu.h<win.h || (cu.h==win.h && cu.m<win.m) || (cu.h==win.h && cu.m==win.m && cu.s<win.s))
{
wait+=(win.h-cu.h)*60 + win.m-cu.m + (win.s-cu.s)/60.0;
win.m+=cu.process;
win.h+=win.m/60;
win.m%=60;
W.push(win);
}
else
{
win.s=cu.s;
win.m=cu.m+cu.process;
win.h+=win.m/60;
win.m%=60;
W.push(win);
}
}
printf("%.1f",wait/N);
}