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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

1017 Queueing at Bank (25 分)_27行代码AC

發(fā)布時間:2024/2/28 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 1017 Queueing at Bank (25 分)_27行代码AC 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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


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


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 (≤10^4) - 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個業(yè)務(wù)窗口,08:00:00點開始辦理業(yè)務(wù),17:01:00準時停止服務(wù)(注意是停止服務(wù),不是停止辦理!!!并且17點來仍然可以服務(wù)。 也就是說如果17點整來一個人辦理一百億年的服務(wù),仍然可以給他辦理。),顧客按順序排隊,求平均等待時間。

明白題意就很好辦了,中規(guī)中矩的寫模擬就行。(方便起見,將循環(huán)拆分成最小的時間片段,也就是秒。)


#include <bits/stdc++.h> using namespace std; typedef struct {int a_time, p_time; }record; int main() {int N, K, cnt = 0, sum = 0;scanf("%d %d", &N, &K);vector<int> time( K, 8 * 60 * 60 );vector<record> rec;for( int i = 0, h, m, s, p; i < N; ++i ) {scanf("%d:%d:%d %d", &h, &m, &s, &p);if( h * 3600 + m * 60 + s <= 17 * 3600 )rec.push_back( { h * 3600 + m * 60 + s, p * 60 } );}sort( rec.begin(), rec.end(), [] ( record a, record b ) { return a.a_time < b.a_time; } );for( int i = 0, min; i < rec.size(); ++i ) {min = 0;for( int j = 0; j < K; ++j )if( time[j] < time[min] ) min = j;if( time[min] > rec[i].a_time ) {sum += time[min] - rec[i].a_time;time[min] += rec[i].p_time;}else time[min] = rec[i].p_time + rec[i].a_time;}printf("%.1f", sum / 60.0 / rec.size() ); }

耗時:


??????——發(fā)現(xiàn)光,追隨光,成為光,發(fā)散光。

總結(jié)

以上是生活随笔為你收集整理的1017 Queueing at Bank (25 分)_27行代码AC的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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