PAT1017. Queueing at Bank

#include<string>
#include<algorithm>
#include<queue>
#include<iostream>
using namespace std;
struct node{
  int come,cost;
  node(string s){
    int a,b,c,d;
    sscanf(s.c_str(),"%d:%d:%d %d",&a,&b,&c,&d);
    come=a*3600+b*60+c;
    cost=d*60;
  }
  bool operator<(const node&x)const{return come>x.come;}
};
int main(){
  int n,k;cin>>n>>k;cin.get();
  vector<int>free(k,8*3600);
  priority_queue<node>que;
  for(int i=0;i<n;++i){
    string s; getline(cin,s);
    if(s>"17:00:00")continue;
    que.emplace(s);
  }for..
  double wait=0,cnt=que.size();
  while(!que.empty()){
    auto x=que.top() ; que.pop();
    int nth=min_element(free.begin(),free.end())-free.begin();
    if(free[nth]>=x.come){
      wait+=free[nth]-x.come;
      free[nth]+=x.cost;
    }else
      free[nth]=x.come+x.cost;
  }//while..
  printf("%.1lf",wait/60/cnt);
}
每个窗口有释放时间,每次队伍头的人找一个最早释放的窗口刷新其释放时间


你可能感兴趣的:(PAT1017. Queueing at Bank)