标签:spec nbsp you names tin 一个人 can window double
Suppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow line, until it is his/her turn to be served and there is a window available. It is assumed that no window can be occupied by a single customer for more than 1 hour.
Now given the arriving time T and the processing time P of each customer, you are supposed to tell the average waiting time of all the customers.
Each input file contains one test case. For each case, the first line contains 2 numbers: N (≤) - the total number of customers, and K (≤) - the number of windows. Then N lines follow, each contains 2 times: HH:MM:SS
- the arriving time, and P - the processing time in minutes of a customer. Here HH
is in the range [00, 23], MM
and SS
are both in [00, 59]. It is assumed that no two customers arrives at the same time.
Notice that the bank opens from 08:00 to 17:00. Anyone arrives early will have to wait in line till 08:00, and anyone comes too late (at or after 17:00:01) will not be served nor counted into the average.
For each test case, print in one line the average waiting time of all the customers, in minutes and accurate up to 1 decimal place.
7 3
07:55:00 16
17:00:01 2
07:59:59 15
08:01:00 60
08:00:00 30
08:00:02 2
08:03:00 10
8.2
题意:
银行中有K个窗口,每个窗口一次只能服务一个人,给出N个人的来到时间和将要被服务的时间,问这N个人的平均等待时间是多少?
思路:
这道题和之前的那道乒乓球俱乐部那道题很像,但是要比那道题简单不少。思路都在代码里很好理解。
Code:
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 const int inf = 0x7fffffff; 6 7 struct People { 8 int arraving_time; 9 int processing_time; 10 }; 11 12 struct Window { 13 int next_time; 14 }; 15 16 bool cmp(People a, People b) { return a.arraving_time < b.arraving_time; } 17 18 int main() { 19 int N, K; 20 scanf("%d %d", &N, &K); 21 int hh, mm, ss, t; 22 vector<People> peoples(N); 23 vector<int> windows(K, 8 * 3600); 24 for (int i = 0; i < N; ++i) { 25 scanf("%d:%d:%d %d", &hh, &mm, &ss, &t); 26 peoples[i].arraving_time = hh * 3600 + mm * 60 + ss; 27 peoples[i].processing_time = t * 60; 28 } 29 sort(peoples.begin(), peoples.end(), cmp); 30 int count = 0; 31 double waiting_time = 0.0; 32 for (int i = 0; i < N; ++i) { 33 if (peoples[i].arraving_time > 17 * 3600) break; 34 int strating_time = inf, index; 35 for (int j = 0; j < K; ++j) { 36 if (strating_time > windows[j]) { 37 index = j; 38 strating_time = windows[j]; 39 } 40 } 41 count++; 42 if (strating_time > peoples[i].arraving_time) { 43 waiting_time += strating_time - peoples[i].arraving_time; 44 windows[index] = strating_time + peoples[i].processing_time; 45 } else { 46 windows[index] = 47 peoples[i].arraving_time + peoples[i].processing_time; 48 } 49 } 50 printf("%.01f\n", waiting_time / (60 * count)); 51 return 0; 52 }
标签:spec nbsp you names tin 一个人 can window double
原文地址:https://www.cnblogs.com/ruruozhenhao/p/13187687.html