此題只要老老實實按題目來不要想太多,,,
例如最後一個點。。。我特判了最後處理完超過五點的情況就按五點處理
想着人家都關銀行了,,你就等到5點就得走了,,結果發現想多了,,
思路:
1.先把超過五點的搞掉,沒來過,沒來過,,
2. 少於窗口 特判8點
3. 等於窗口數,拉出隊列中最早結束的那個,與現在這個對比,如果發現現在那位要等最早那位一會,那就時間加上唄
注:全部搞爲秒來會很舒服
代碼如下:
#include <bits/stdc++.h>
using namespace std;
struct stu{
int times; //到達時間
int P; //處理時間
}ren[10005];
double avtime;
priority_queue <stu> que;
bool operator < (const stu &A , const stu &B){
return A.times > B.times;
} //已經在辦事的人按誰早誰出來
int comp(stu A, stu B){
return A.times < B.times;
} //等待的人按時間排
const int eight = 8*3600,fif = 17 * 3600;//直接化秒
int main()
{
int N,wins,s,f,m,pp,sumtime,n = 0;
scanf("%d%d",&N,&wins);
for (int i = 0; i < N; i++){
scanf("%d:%d:%d %d",&s,&f,&m,&pp);
sumtime = s*3600 + f*60 +m;
pp *= 60;
if( sumtime >= fif) continue; //超時了
else {
ren[n].times = sumtime;
ren[n++].P = pp;
}
//存檔時間
}
sort(ren,ren+n,comp);
//走位走位
//對每個進入的人繼續時間計算即可
for (int i = 0; i < n; i++)
{
stu nows;
if(que.size() < wins){ //少於窗口數 特判八點
if(ren[i].times < eight) {
avtime += eight - ren[i].times;
ren[i].times = eight;
}
}
else{
stu lasts;
lasts = que.top(); que.pop();
if(lasts.times > ren[i].times) { //如果要等
avtime += lasts.times - ren[i].times;
ren[i].times = lasts.times;
}
}
nows.times = ren[i].P + ren[i].times;
que.push(nows);
}
avtime /= n*60;
printf("%.1f",avtime);
return 0;
}