-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpat_advance_1017.cpp
63 lines (62 loc) · 1.21 KB
/
pat_advance_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
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct data{
int cTim, pTime;
};
bool cmp(data a, data b){
return a.cTim < b.cTim;
}
int main(){
int n, k;
cin >> n >> k;
vector<data> v;
vector<int> windows(k, 28800);
data temp;
int hour, min, sec, p, totalTime;
int waitTime = 0;
/*input data match the requirment*/
for (int i = 0; i < n; i++)
{
scanf_s("%d:%d:%d %d", &hour, &min, &sec, &p);
if (p > 60)
p = 60;
totalTime = hour * 3600 + min * 60 + sec;
if (totalTime > 61200)
continue;
temp.cTim = totalTime;
temp.pTime = p*60;
v.push_back(temp);
}
sort(v.begin(), v.end(), cmp);
/*begin operation*/
int index = 0;
while (index < v.size()){
int minTime = windows[0], minNum = 0;
/*find the minimun window*/
for (int i = 1; i < k; i++)
{
if (minTime > windows[i]){
minTime = windows[i];
minNum = i;
}
}
if (v[index].cTim < windows[minNum]){
waitTime += windows[minNum] - v[index].cTim;
windows[minNum] += v[index].pTime;
}
else{
windows[minNum] = v[index].cTim + v[index].pTime;
}
index++;
}
if (waitTime == 0){
printf("0.0\n");
}
else{
printf("%.1f", waitTime / 60.0 / v.size());
}
return 0;
}