其他分享
首页 > 其他分享> > PAT 甲级 1014 Waiting in Line

PAT 甲级 1014 Waiting in Line

作者:互联网

用队列模拟结束时间最轻便

#include<bits/stdc++.h>
using namespace std;

const int N = 1010;

int finish[N];

unordered_map<int,int> ans;

queue<int> q[N];

int main(){
    int n,m,k,qry;
    int t;
    cin>>n>>m>>k>>qry;
    for(int i=1;i<=k;i++){
        cin>>t;
        int tmp=1;
        if(i<=n*m){
            for(int j=1;j<=n;j++){
                if(q[j].size()<q[tmp].size())
                    tmp=j;
            }
        }
        else{
            for(int j=1;j<=n;j++){
                if(q[j].front()<q[tmp].front())
                    tmp=j;
            }
        }
        if(i>n*m) q[tmp].pop(); 
        q[tmp].push(finish[tmp]+t);
        finish[tmp]+=t;
        if(finish[tmp]-t<540) ans[i]=finish[tmp];
    }
    while(qry--){
        cin>>t;
        if(ans.count(t)) printf("%02d:%02d\n",ans[t]/60+8,ans[t]%60);
        else puts("Sorry");
    }
    return 0;
}

标签:tmp,02d,finish,PAT,int,60,Waiting,ans,1014
来源: https://www.cnblogs.com/xhy666/p/16230186.html