首页 > 学院 > 开发设计 > 正文

1017. Queueing at Bank (25)

2019-11-08 20:10:19
字体:
来源:转载
供稿:网友
#include<iostream>#include<stdio.h>#include<vector>#include<algorithm>#include<deque>#include<iomanip>using namespace std;long long int wait=0;int cus_count;typedef struct{ int t; int p;}customer;bool compare_customer(customer x,customer y){ return x.t < y.t;}deque<customer> cusv;deque<customer> cusw;int window[101];int main(){ int N,K; cin>>N>>K; for(int t=0;t<N;t++) { int h,m,s,p; customer temp; scanf_s("%d:%d:%d %d",&h,&m,&s,&p); if(h<17 || (h==17&&m==0&&s==0)) { temp.t=h*3600+m*60+s; p = p > 60 ? 60 : p; temp.p=p*60; cusv.push_back(temp); } } sort(cusv.begin(),cusv.end(),compare_customer); cus_count = cusv.size(); for(unsigned int t=0;t<cusv.size();t++) cusv[t].t-=8*3600; while (cusv.size() != 0 && cusv.front().t <= 0) { wait -= cusv.front().t; cusw.push_back(cusv.front()); cusv.pop_front(); } for (int t = 0;t < K;t++) window[t] = 0; for (int tt = 0;tt < K;tt++) { if (window[tt]==0 && cusw.size()!=0) { window[tt] = cusw.front().p; cusw.pop_front(); } } while(cusw.size()!=0 || cusv.size()!=0 ) { wait += cusw.size(); for (auto &x : cusv) --x.t; while (cusv.size()!=0 && cusv.front().t== 0) { cusw.push_back(cusv.front()); cusv.pop_front(); } for (int tt = 0;tt < K;tt++) if (window[tt]!=0) window[tt]--; for (int tt = 0;tt < K;tt++) { if (window[tt]==0 && cusw.size()!=0) { window[tt] = cusw.front().p; cusw.pop_front(); } } } double ttt = (double)wait / 60/cus_count; cout << setPRecision(1) << fixed << ttt << endl;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表