日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

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

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

立志用最少的代碼做最高效的表達(dá)


PAT甲級(jí)最優(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個(gè)業(yè)務(wù)窗口,08:00:00點(diǎn)開(kāi)始辦理業(yè)務(wù),17:01:00準(zhǔn)時(shí)停止服務(wù)(注意是停止服務(wù),不是停止辦理!!!并且17點(diǎn)來(lái)仍然可以服務(wù)。 也就是說(shuō)如果17點(diǎn)整來(lái)一個(gè)人辦理一百億年的服務(wù),仍然可以給他辦理。),顧客按順序排隊(duì),求平均等待時(shí)間。

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


#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() ); }

耗時(shí):


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

總結(jié)

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

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