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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

PAT 1017 Queueing at Bank[一般]

發布時間:2025/3/15 编程问答 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PAT 1017 Queueing at Bank[一般] 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1017?Queueing at Bank (25)(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 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
?(25)(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 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

AC:

#include<iostream> #include<stdio.h> #include<algorithm> using namespace std; struct co{int arrive;int begn;int serve;int wait; };bool cmp( co a , co b){return a.arrive<b.arrive; }int main() {int n,k;int hh,mm,ss,ser,sum=0;scanf("%d%d",&n,&k);co * Co=new co[10000];if(0>=n||0>=k){printf("0.0");return 0;}int beg=8*3600;for(int i=0;i<n;i++){scanf("%d:%d:%d %d",&hh,&mm,&ss,&ser);//到達是不同時到達的,//共32400sCo[sum].arrive=hh*3600+mm*60+ss-beg;//轉換成秒Co[sum].serve=ser*60;if(Co[sum].arrive<32400)sum++;//sum表示一共有多少人。//我的媽呀,if里的sum寫成了i。。。。導致代碼通不過,醉了。 }n=sum;sort(Co,Co+n,cmp);//按到達時間排序。int win[k];//表示當前窗口都沒人;為什么我一開始這里定義為3,一定是氣懵了。。。。fill(win,win+k,-1);int no=0;//還剩下多少人需要服務。for(int tm=0;no!=n;tm++){//int tm=0;tm<32400;tm++,一開始for循環條件是這個,但是發現了問題,//如果這樣的話,就不能保證所有在17:00之前到的顧客都能服務了。if(no==n)break;for(int i=0;i<k;i++){if(win[i]!=-1){if(Co[win[i]].begn+Co[win[i]].serve==tm){//當前正好有結束的。//下一位顧客進來win[i]=-1;}}}for(int i=0;i<k;i++){//如果有空,那么就開始放。if(win[i]==-1&&Co[no].arrive<=tm){Co[no].begn=tm;win[i]=no;no++;if(no==n)break;}}} // for(int i=0;i<n;i++){ // printf("\n%d %d %d\n",Co[i].arrive,Co[i].begn,Co[i].serve); // }long long total=0;int miu=0;for(int i=0;i<n;i++){total+=(Co[i].begn-Co[i].arrive); // if(total%60==0){ // miu+=total/60; // total=0; // } }//miu+=1.0*total/60;//在這里不會四舍五入!!!printf("%.1f",total/60.0/n);return 0; } /** 2 2 8:00:05 1 12:00:00 1**/

//對我自己醉了,通不過就是因為瞎。。心瞎。。遇到了段錯誤,原來是自己一開始定義數組就錯了。之后還答案錯誤,原來是數組下標寫錯了。感謝牛客網,通不過的話會有樣例,能根據樣例去修改代碼!

?

轉載于:https://www.cnblogs.com/BlueBlueSea/p/9384980.html

總結

以上是生活随笔為你收集整理的PAT 1017 Queueing at Bank[一般]的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。