/
1017.c
64 lines (53 loc) · 1.37 KB
/
1017.c
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
#include <stdio.h>
#include <stdlib.h>
typedef struct Customer{
int start, len;
}Customer;
/* Compare two Customer stucture by start time */
int cmp(const void *a, const void *b)
{
Customer c1 = *(Customer*)a;
Customer c2 = *(Customer*)b;
return c1.start - c2.start;
}
int main()
{
int N, K, earliest, i;
int HH, MM, SS;
int wait_time = 0, queue_time[100] = {0};
Customer customers[10000], *p;
scanf("%d %d", &N, &K);
for (int i = 0; i < N; i++) {
scanf("%d:%d:%d %d", &HH, &MM, &SS, &customers[i].len);
/* Relative time to 08:00:00 */
customers[i].start = SS + 60 * (MM + 60 * (HH - 8));
customers[i].len *= 60;
}
qsort(customers, N, sizeof(Customer), cmp);
for (i = 0; i < N; i++) {
p = customers + i;
/* Find the queue number which will finish next */
earliest = 0;
for (int i = 0; i < K; i++)
if (queue_time[i] < queue_time[earliest])
earliest = i;
/* later than 17:00:00 */
if (p->start > (17 - 8) * 3600)
break;
/* processing time longer than one hour */
if (p->len > 3600)
p->len = 3600;
/* increase total waiting time and modify the time of each queue */
if (p->start < queue_time[earliest]) {
wait_time += queue_time[earliest] - p->start;
queue_time[earliest] += p->len;
} else {
queue_time[earliest] = p->start + p->len;
}
}
if (i)
printf("%.1f", wait_time / 60.0 / i);
else
printf("0.0");
return 0;
}