PAT甲級-1014. Waiting in Line (30)(模擬)
1014. Waiting in Line (30)
Suppose a bank has N windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rules for the customers to wait in line are:
- The space inside the yellow line in front of each window is enough to contain a line with M customers. Hence when all the N lines are full, all the customers after (and including) the (NM+1)st one will have to wait in a line behind the yellow line.
- Each customer will choose the shortest line to wait in when crossing the yellow line. If there are two or more lines with the same length, the customer will always choose the window with the smallest number.
- Customer[i] will take T[i] minutes to have his/her transaction processed.
- The first N customers are assumed to be served at 8:00am.
Now given the processing time of each customer, you are supposed to tell the exact time at which a customer has his/her business done.
For example, suppose that a bank has 2 windows and each window may have 2 customers waiting inside the yellow line. There are 5 customers waiting with transactions taking 1, 2, 6, 4 and 3 minutes, respectively. At 08:00 in the morning, customer1 is served at window1 while customer2 is served at window2. Customer3 will wait in front of window1 and customer4 will wait in front of window2. Customer5 will wait behind the yellow line.
At 08:01, customer1 is done and customer5 enters the line in front of window1 since that line seems shorter now. Customer2 will leave at 08:02, customer4 at 08:06, customer3 at 08:07, and finally customer5 at 08:10.
Input
Each input file contains one test case. Each case starts with a line containing 4 positive integers: N (<=20, number of windows), M (<=10, the maximum capacity of each line inside the yellow line), K (<=1000, number of customers), and Q (<=1000, number of customer queries).
The next line contains K positive integers, which are the processing time of the K customers.
The last line contains Q positive integers, which represent the customers who are asking about the time they can have their transactions done. The customers are numbered from 1 to K.
Output
For each of the Q customers, print in one line the time at which his/her transaction is finished, in the format HH:MM where HH is in [08, 17] and MM is in [00, 59]. Note that since the bank is closed everyday after 17:00, for those customers who cannot be served before 17:00, you must output "Sorry" instead.
Sample Input2 2 7 5 1 2 6 4 3 534 2 3 4 5 6 7Sample Output
08:07 08:06 08:10 17:00 Sorry
題目意思:
銀行早晨8點上班,17點結束接待視窗以外的客戶。
給出銀行視窗數目N、每個視窗前黃線內允許等待的人數M、K個客戶處理各自業務需
要的時間、查詢的Q個客戶編號。
輸出客戶辦理完業務的時間,如果不能辦理就輸出Sorry。
解題思路:
1、所有能進黃線的客戶人數是N*M,其他客戶在外面等著;
2、當有客戶處理完畢,黃線內有空時,黃線外等待的客戶挑選視窗的順序是:等待人
數最少、時間最早、編號最小;
3、已經在黃線內的客戶不能到別的視窗前排隊;
4、客戶只要是在17點之前坐到視窗就可以辦理業務,而不是業務結束時間在17點之
前,也就是說WindowStartTime>=17:00時,輸出Sorry。
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define MAXN 1010
struct Node
{
int no,sh,sm,eh,em;//客戶編號、花費時間、結束時間
bool vis;//是否處理完畢
} t[MAXN];//客戶
struct Win
{
int no,wh=8,wm=0,num=0;//視窗編號、營業時間、當前客戶數
queue<Node>que;//每個視窗的隊伍
} w[20];//視窗
bool cmp(Win a,Win b)//注意視窗排序關鍵字
{
if(a.num!=b.num) return a.num<b.num;
else if(a.wh!=b.wh) return a.wh<b.wh;
else if(a.wm!=b.wm) return a.wm<b.wm;
return a.no<b.no;
}
bool flagEmpty(int n)//所有視窗業務是否都處理完畢
{
for(int i=0; i<n; ++i)
if(!w[i].que.empty()) return false;
return true;
}
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("D:/x/read.txt","r",stdin);
//freopen("D:/x/out.txt","w",stdout);
#endif
//ios::sync_with_stdio(false);
//cin.tie(0);
int n,m,k,Q;//視窗、黃線、客戶、查詢
cin>>n>>m>>k>>Q;
for(int i=0; i<k; ++i)
{
int x;
cin>>x;
t[i].sh=x/60;
t[i].sm=x%60;
t[i].vis=true;
t[i].no=i;//客戶編號
}
for(int i=0; i<n; ++i) w[i].no=i;
int cnt=0,wait=k;//已受理和等待的服務人數
while(1)
{
if(cnt==k&&flagEmpty(n)) break;//黃線後沒有客戶等待且所有視窗業務都處理完畢
sort(w,w+n,cmp);//按視窗處理結束時間排序
for(int j=0; j<m; ++j) //黃線內
for(int i=0; i<n; ++i) //讓黃線後的客戶去視窗排隊
if(w[i].que.size()<m&&wait>0)
{
w[i].que.push(t[cnt]);
++cnt,--wait,++w[i].num;
if(cnt==k) goto A;//黃線後沒有客戶等待
}
A:
for(int i=0; i<n; ++i) //處理各個視窗的客戶業務
{
if(w[i].que.empty()) continue;
Node temp=w[i].que.front();
w[i].que.pop();
int no=temp.no;//獲取客戶編號
--w[i].num;
if(w[i].wh>=17||w[i].wh<8) t[no].vis=false;//不在服務時間內
else
{
t[no].eh=w[i].wh+temp.sh+(w[i].wm+temp.sm)/60;
t[no].em=(w[i].wm+temp.sm)%60;
w[i].wh=t[no].eh;
w[i].wm=t[no].em;
}
}
}
while(Q--)//查詢
{
int q;
cin>>q;
--q;
if(!t[q].vis) puts("Sorry");
else printf("%02d:%02d\n",t[q].eh,t[q].em);
}
return 0;
}
相關文章
- 【PAT甲級A1038】Recover the Smallest Number (30分)(c++)C++
- PAT甲級1126~1130|C++實現C++
- PAT甲級1023 Have Fun with Number
- PAT 甲級 1152 Google Recruitment (20分)GoUI
- PAT甲級考試題庫題目分類
- (非原創)PAT甲級1123 Is It a Complete AVL Tree (30分)|C++實現C++
- PAT甲級-1005. Spell It Right (20)各位之和
- 【PAT甲級A1084】Broken Keyboard (20分)(c++)C++
- PAT甲級-1010. Radix (25)進位制
- PAT甲級-1012. The Best Rank (25)並列排序排序
- 2024 秋季PAT認證甲級(題解A1-A4)
- PAT甲級1154 Vertex Coloring (25分)|C++實現C++
- PAT-B 1067 試密碼【模擬】密碼
- PAT甲級1122 Hamiltonian Cycle (25分)|C++實現C++
- 2021.9.12週六PAT甲級考試覆盤與總結
- 【PAT甲級A1065】A+B and C (64bit) (20分)(c++)C++
- PAT-B 1059 C語言競賽【模擬】C語言
- PAT-B 1081 檢查密碼【模擬】密碼
- PTA甲級 1076 Forwards on Weibo (30分)Forward
- 10.30 模擬賽
- PAT甲級1110 Complete Binary Tree (25分)|C++實現C++
- 安卓模擬器顯示offline安卓
- 菜鳥記錄:c語言實現PAT甲級1010--RadixC語言
- PAT-B 1019 數字黑洞【陣列+模擬】陣列
- PAT-B 1024 科學計數法【模擬+字串】字串
- 2024.3.30 模擬賽
- PAT-B 1077 互評成績計算【模擬】
- Waiting for target device to come onlineAIdev
- [PAT]Table Tennis (30)Java實現Java
- PAT B1036 跟奧巴馬一起程式設計(簡單模擬)程式設計
- SSK:超級鍵盤模擬器,呼叫底層,可模擬所有按鍵
- PAT-B 1008 陣列元素迴圈右移問題【簡單模擬】陣列
- 【PAT乙級】1048 數字加密加密
- 8.30 上午 becoder 模擬賽總結 & 題解
- 模擬
- Python 計算機二級模擬題賞析Python計算機
- 2024.9.6 CF1307 模擬賽記錄
- 10.6 模擬賽(NOIP 模擬賽 #9)