[PAT甲級]1017. Queueing at Bank (25)(銀行辦理業務平均等待時間)
1017. Queueing at Bank (25)
原題連結
相似題目 1014. Waiting in Line (30)
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.
Input Specification:
Each input file contains one test case. For each case, the first line contains 2 numbers: N (<=10000) - the total number of customers, and K (<=100) - 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.
Output Specification:
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.
Sample Input:
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
Sample Output:
8.2
題目大意:
- 銀行排隊辦理業務,有N個人,K個視窗
- 給出N個人的到達銀行時間,個人辦理業務所需要的時間,求平均等待時間
- 銀行視窗08:00開始辦理業務,下午17:00之後到達的人不接受辦理,不算有效的人
- 每個視窗前只能有一個人辦理業務,其他的人均在黃線外等待,有視窗最先空閒(前一個人辦理業務結束),等待的顧客就可以按照到達時間的先後順序去辦理
思路:
- 定義結構體記錄顧客到達時間come,辦理業務所需要時間time
- 為了方便計算,時間全部換成秒來計算
- 統計並篩選所有辦理業務的人,剔除17:00以後到達的人,按照到達時間排序
- 如果顧客到達時間come大於視窗空閒時間windowTime,就可以直接辦理業務,無需等待,否則等待總時間res += (windowTime - come)
- 最終 等待總時間res/60/ 辦理業務有效人數 = 人均等待時間
- 注意res按秒計算,先換成分鐘,再求平均等待時間
程式碼:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
struct node{
int come;//到達時間
int time;//辦理業務所需要時間
};
int cmp(node a, node b){
return a.come < b.come;
}
int main()
{
int n, k;//n個人 k個視窗
scanf("%d %d", &n, &k);
vector<node> custom;
for(int i=0; i<n; i++){
int hh,mm,ss,time;
scanf("%d:%d:%d %d", &hh, &mm, &ss, &time);
int cometime = hh*3600 + mm*60 + ss;
if(cometime > 61200)//顧客來的時間晚於17:00 無效 直接跳過,無法辦理
continue;
node temp;
temp.come = cometime;
temp.time = time*60;
custom.push_back(temp);
}
sort(custom.begin(), custom.end(), cmp);
vector<int> windowTime(k, 28800);//28800代表早上八點
double res = 0.0;
for(int i=0; i<custom.size(); i++){
int minWindow=0;//最早結束的視窗 最早結束的視窗時間
for(int j=1; j<k; j++){
if(windowTime[minWindow] > windowTime[j]){
minWindow = j;
}
}
if(windowTime[minWindow] <= custom[i].come){//顧客來的時候就有空閒視窗
windowTime[minWindow] = custom[i].come + custom[i].time;
}else{//顧客來的時候需要等待
res += (windowTime[minWindow] - custom[i].come);//顧客等待時間
windowTime[minWindow] += custom[i].time;//更新視窗空閒時間
}
}
if(custom.size() == 0){//有效人數為0,直接輸出,除以0無意義
printf("0.0");
}else{
printf("%.1f", res/60.0/custom.size());
}
return 0;
}
相關推薦
[PAT甲級]1017. Queueing at Bank (25)(銀行辦理業務平均等待時間)
1017. Queueing at Bank (25) 原題連結 相似題目 1014. Waiting in Line (30) Suppose a bank has K windows open for service. There is a yello
PAT 甲級 1017. Queueing at Bank
最後一個例子沒過 不過有巨巨發現我程式碼的bug,為什麼最後一個例子沒過,請聯絡我 #include<stdio.h> #include<algorithm> #include<vector> #include<queue>
PAT 甲級 1017 Queueing at Bank
-o n) true rst pos for %d from sum https://pintia.cn/problem-sets/994805342720868352/problems/994805491530579968 Suppose a bank has K
PAT 1017. Queueing at Bank (25) 屢次段錯誤,終於過了
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 cust
PAT 1017. Queueing at Bank (25)
// //1017. Queueing at Bank (25) // accept #include <iostream> #include <algorithm> using namespace std; typedef struct {
1017 Queueing at Bank (我自己寫的模擬時間的版本)
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 custom
PAT 1017 Queueing at Bank (25 分)燚
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 part
PAT 1017 Queueing at Bank[一般]
problem lis iostream n) using ber 數組下標 pos card 1017 Queueing at Bank (25)(25 分)提問 Suppose a bank has K windows open for service. Ther
1017 Queueing at Bank (25 分)【模擬】
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.
PAT 1017 Queueing at Bank
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
pat 1017. Queueing at Bank (模擬優先佇列)
好久沒有做pat了,重新開刷 本想從這道水題入手可以快點,結果卻慘遭滑鐵盧,到第二天才全部通過 廢話說完看題,模擬題,模擬的是多視窗排隊。 建議把時間統一轉化為秒做處理。 我選擇了用map儲存依次到達的顧客(題設保證了到達時間都不相同),用priority_queue模擬
1017 Queueing at Bank
tar 客戶 題意 continue 參與 custom div using 窗口 題意:銀行有K個窗口用於服務,給出所有人的達到時間T和服務時間P,計算所有被服務的客戶的平均等待時間。任何客戶的服務時間不得超過60分鐘。早於08:00到的,要等到08:00;在17:00:
1017 Queueing at Bank - 優先佇列+模擬
題意: 有n個人k個視窗,每個視窗服務一個人,顧客按到來的先後順序排隊,當視窗沒人的時候,就過去,問平均等待時間 思路: 這種時間題肯定要先轉為秒,這樣好算啦 然後顧客要是在8點之前到的話要等待 程式碼如下: #include<iostream> #include
PAT1017:Queueing at Bank
scan ssi spec pen contain 內存 兩種 end output 1017. Queueing at Bank (25) 時間限制 400 ms 內存限制 65536 kB 代碼長度限制 16000 B 判題程序 Standard 作者
PAT甲級 1101 Quick Sort (25 分) 快排
1101 Quick Sort (25 分) There is a classical process named partition in the famous quick sort algorithm. In this process we typic
PAT甲級 1063 Set Similarity (25 分)Set集合
1063 Set Similarity (25 分) Given two sets of integers, the similarity of the sets is defined to be Nc/Nt×100%, where Nc is the n
1017 Queueing at [email protected]
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 par
PAT甲級1017 (模擬排序)
課前分析 感覺和1016差不多, 就模擬一下幾個佇列, 有空位立即插入並計算等待時間, 沒空位計算最早處理完的使用者的離去時間,並更新為當前時間等等。 (1) vector a(10); //定義了10個整型元素的向量(尖括號中為元素型別名,它可以是任何合法的資
PAT甲級 1083 List Grades (25 分)排序水題
1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed to sort the records with respect to t
PAT甲級 1101 Quick Sort (25 分) 快排
1101 Quick Sort (25 分) There is a classical process named partition in the famous quick sort algorithm. In this process we typically choo