日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【一遍过!!!】1014 Waiting in Line (30 分)(题意+分析)

發(fā)布時間:2024/2/28 编程问答 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【一遍过!!!】1014 Waiting in Line (30 分)(题意+分析) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

立志用最少的代碼做最高效的表達


PAT甲級最優(yōu)題解——>傳送門


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.
?? 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 custmers 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, customer

Input Specification:
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 Specification:
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 Input:
2 2 7 5
1 2 6 4 3 534 2
3 4 5 6 7

Sample Output:
08:07
08:06
08:10
17:00
Sorry


題意:K個人,N個窗口,每個窗口分為黃線內(nèi)和黃線外, 每個窗口黃線內(nèi)可以站M個人。
最初按窗口順序在黃線里排隊,如果黃線里排滿,則統(tǒng)一排到黃線外(只有一個隊列)。
當(dāng)某一窗口有一個人辦理完業(yè)務(wù),黃線外的第一個人立刻補充到該窗口黃線內(nèi)的隊伍里。

老老實實寫模擬即可。

解題思路:由于最后需要按編號查詢, 因此定義結(jié)構(gòu)體,元素有編號、所需時間、完成時間等等。然后定義結(jié)構(gòu)體隊列, 將時間簡化為分鐘,一分鐘一次循環(huán), 接下來對每個隊列進行操作即可。

細(xì)節(jié):

  • 如果K<M*N, 那么入隊列的人以K為準(zhǔn)
  • 如果到了17點,顧客還沒有被服務(wù)(注意是被服務(wù))。 那么輸出sorry
  • (PS:抱著Debug的決心敲得代碼,反反復(fù)復(fù)調(diào)試確認(rèn)了很久才提交代碼,結(jié)果一遍過,太開心了!)


    #include<bits/stdc++.h> using namespace std;struct costomer{int id, n_t1, n_t2, f_t; //編號、所需時間、實際完成時間 int h, m; //完成的小時數(shù),分鐘數(shù) }; bool cmp(costomer c1, costomer c2) {return c1.id < c2.id; //id號升序排列 }int main() {int N, M, K, Q; cin >> N >> M >> K >> Q;queue<costomer>q[N];int id = 1;//處理前M*N個顧客 int Min = min(M, K); while(1) {for(int j = 0; j < N; j++) {costomer cos;int t; cin >> t;cos.id = id++;cos.n_t1 = cos.n_t2 = t;q[j].push(cos);if(id > min(M*N, K)) goto loop; //滿足條件則退出循環(huán) }}loop : ;int now_cos_num = max(K-M*N, 0); //剩余未處理的乘客 vector<costomer>fin; //存放結(jié)果 int t = 0;while(1) { //每次循環(huán)都是一分鐘 t++;int temp = 0; for(int i = 0; i < N; i++) { //每一分鐘所有窗口同時-1 if(!q[i].empty()) { //如果隊列非空 q[i].front().n_t1--;if(q[i].front().n_t1 == 0) { //如果剩余處理時間為0 q[i].front().f_t = t; //壓入結(jié)果隊列 costomer cos = q[i].front();q[i].pop();fin.push_back(cos); //結(jié)果序列存放該顧客if(now_cos_num-- > 0) { //如果還有剩余顧客 int x; cin >> x; //輸入,壓入隊列 cos.id = id++; cos.n_t1 = cos.n_t2 = x; cos.f_t = 0;q[i].push(cos);}}} else { //如果空了,代表沒有后續(xù)的人,temp++。 temp++; }}if(temp == N) break; //如果temp=窗口數(shù),則說明無人,返回。 }sort(fin.begin(), fin.end(), cmp); for(int i = 0; i < Q; i++) {int x; cin >> x; x-=1;if(fin[x].f_t-fin[x].n_t2 >= 540) cout << "Sorry\n";else printf("%02d:%02d\n", fin[x].f_t/60+8, fin[x].f_t%60);}return 0; }

    耗時:


    ????????——錯過落日余暉,請記得還有漫天星辰。

    總結(jié)

    以上是生活随笔為你收集整理的【一遍过!!!】1014 Waiting in Line (30 分)(题意+分析)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: av男人的天堂在线观看 | 动漫美女无遮挡免费 | 国产男女猛烈无遮挡免费视频动漫 | 91免费在线观看网站 | 自拍偷拍欧美激情 | 欧美.com | 潘金莲一级淫片aaaaaa播放 | 国产a√精品区二区三区四区 | 久久精品国产一区二区电影 | 亚洲一区精品视频在线观看 | 插插插av| 国产一区在线免费 | 久久成人黄色 | 色偷偷888欧美精品久久久 | 成人综合影院 | 国产高清在线观看视频 | 国产二区三区 | 亚洲狠狠 | 噜噜在线视频 | 亚洲免费色 | 大战熟女丰满人妻av | 色婷婷中文 | 男人操女人逼逼视频 | 国产三级午夜理伦三级 | www.亚洲综合 | 色婷婷狠 | 久久夜视频 | 无码少妇一区二区 | av伦理在线 | 亚洲精选一区二区 | 欧美交换国产一区内射 | 国产91在线视频观看 | 五月婷婷综合激情 | 偷自在线 | 一区二区三区日韩欧美 | 色婷婷综合在线 | 亚洲精品在线观看视频 | 久久av喷吹av高潮av萌白 | 黄色网av | 黄色网页入口 | 久久精品无码一区二区三区 | 999超碰 | a级在线视频| 热久久精品 | 日韩精彩视频 | 在线观看视频日韩 | 久久精品大全 | 欧美亚洲免费 | 黄色网战大全 | 黄色av网页| 国产精品成人久久久久久久 | 国内露脸中年夫妇交换 | 欧美爱爱爱 | 一区二区三区在线观看av | 精品麻豆av| 日韩一级欧美一级 | 亚洲天堂男人 | 精品国产免费一区二区三区 | 国产亚洲精品电影 | 婷婷亚洲综合五月天小说 | 69精品在线观看 | www.色悠悠 | 女优一区二区三区 | 综合av第一页 | 国产三级漂亮女教师 | 中文字幕第80页 | 日韩在观看线 | 一区二区三区精品在线观看 | www免费黄色 | 88福利视频 | 加勒比在线一区 | 狠狠地日 | 秋霞7777鲁丝伊人久久影院 | 貂蝉被到爽流白浆在线观看 | www久久99 | 亚洲人性生活视频 | 成年人免费视频播放 | 五月婷婷丁香 | 欧美风情第一页 | 午夜日韩欧美 | 亚洲色成人一区二区三区小说 | 中文字幕15页 | www.超碰在线.com| 亚洲激情偷拍 | 一级片在线播放 | 九色91popny蝌蚪新疆 | 日本性久久 | 狂野欧美性猛交xxⅹ李丽珍 | 色综合视频| 女同在线视频 | 成为性瘾网黄的yy对象后 | 在线免费观看av网址 | 国产全是老熟女太爽了 | 青草福利 | 污污网站免费 | 国产农村妇女毛片精品 | 少妇性色av | 毛片毛片毛片毛片毛片毛片毛片 | 黄污视频在线播放 |