用优先队列模拟银行窗口,对等待队伍用List,并进行一次排序。
但是不知道为什么总通不过分值最大的第一个case,后面的13分case倒是通过了。anyway,以后再来啃。
附AC:http://blog.youkuaiyun.com/sunbaigui/article/details/8657074
#include<iostream>
#include<iomanip>
#include<queue>
#include<list>
#include<algorithm>
using namespace std;
struct customer
{
int h;
int m;
int s;
int pt;//process theTime, in minutes
int wt;//wait theTime, in second
bool operator < (const customer& t) const
{
return (h<t.h?true:((h==t.h && m<t.m)?true:((h==t.h && m==t.m && s<t.s)?true:false)));
}
};
struct window
{
int h;
int m;
int s;
bool operator < (const window& t) const
{
return (h>t.h?true:((h==t.h && m>t.m)?true:((h==t.h && m==t.m && s>t.s)?true:false)));
}
};
list<struct customer> wl;//wait line
priority_queue<window> wq;//window priority queue
int TWT=0;//total wait theTime, in second;
int N=0;
int K;
int main()
{
cin>>N>>K;
//input customers
struct customer t;
for(int i=0;i<N;i++)
{
cin>>t.h;getchar();cin>>t.m;getchar();cin>>t.s;cin>>t.pt;
if(t.h<8)
{
t.wt=((8-t.h)*60-t.m)*60-t.s;
t.h=8;
t.m=0;
t.s=0;
}
else
t.wt=0;
if(t.h<17|| (t.h==17&&t.m==0&&t.s==0))
wl.push_back(t);
}
wl.sort();
N=wl.size();
//initial window priority queue
struct window w;
for(int i=0;i<K;i++)
{
w.h=8;
w.m=0;
w.s=0;
wq.push(w);
}
//do work
struct window tw;
struct customer tc;
while(!wl.empty())
{
tw=wq.top();
wq.pop();
tc=wl.front();
if(tc.h>tw.h || (tc.h==tw.h && tc.m>tw.m) || (tc.h==tw.h && tc.m==tw.m && tc.s>=tw.s) )
{
TWT+=tc.wt;
tw.h=tc.h+(tc.m+tc.pt)/60;
tw.m=(tc.m+tc.pt)%60;
tw.s=tc.s;
}
else
{
TWT=TWT+((tw.h-tc.h)*60+tw.m-tc.m)*60+tw.s-tc.s+tc.wt;
int carry=(tw.m+tc.pt)/60;
tw.m=(tw.m+tc.pt)%60;
tw.h+=carry;
}
wq.push(tw);
wl.pop_front();
}
if(N!=0)
cout<<fixed<<setprecision(1)<<(1.0*TWT/60/N)<<endl;
else
cout<<"0"<<endl;
return 0;
}