PTA 甲级 1014 Waiting in Line (30 分)(测试点4,5)

题目:1014 Waiting in Line (30 分)

在这里插入图片描述
在这里插入图片描述
题解:注意事项!!!血的教训
1.首先就是只要在17:00之前接受服务的客户,及时截止时间超过17:00,也是会被服务的,也就是说不能输出sorry
2.注意n、m的取值,如果两个等于0 ???所以这里对队列的处理最好是i<=n*m。这个错误找了好久,看我下面那个注释掉的,就是窗口前的第1位和后面m-1位拆开来处理了,会导致错误的发生

#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef pair<int ,int> PII;
const int N=1010;
const int mod=100000007;
const int MAXX=0x3f3f3f3f;
int n,m,K,Q;
typedef struct Node{
    int id;
    int time;
}node;
typedef struct Que{
    int w_id;
    int ed;
    node no;
    bool operator<(const struct Que & a)const{
        if(ed!=a.ed)return ed>a.ed;
        return w_id>a.w_id;
    }
}que;
node nd[N];
int query[N];
int records[N];
int main(){
    cin>>n>>m>>K>>Q;
    priority_queue<que>  q;
    queue<node> qu[25];
    int k=1;
    for(int i=1;i<=K;i++){
        cin>>nd[i].time;
        nd[i].id=i;
    }
    for(int i=1;i<=Q;i++){
        cin>>query[i];
    }
    //预处理队列
    /*
    for(int i=1;i<=n;i++){
        que t;
        t.w_id=i;
        if(k<=K){
            t.ed=nd[k].time;
            t.no=nd[k];
            k++;
        }else t.ed=MAXX;
        q.push(t);
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<m;j++){
            if(k<=K){
                qu[i].push(nd[k++]);
            }
        }
    }
    */
    for(int i=1;i<=n*m;i++){
        if(i<=n){
            que t;
            t.w_id=i;
            if(k<=K){
                t.ed=nd[k].time;
                t.no=nd[k];
                k++;
            }else t.ed=MAXX;
            q.push(t);
        }else{
            if(k<=K){
                if(i%n==0)
                    qu[n].push(nd[k++]);
                else
                    qu[i%n].push(nd[k++]);
            }
        }
    }
    //cout<<"1:"<<endl;
    memset(records,-1,sizeof records);
    int Time=0;
    while(1){
        que t=q.top();
        if(t.ed==0x3f3f3f3f) break;
        if(Time<t.ed) {
            Time=t.ed;
            continue;
        }
        q.pop();
        records[t.no.id]=t.ed;
        if(qu[t.w_id].size()){
            que tmp;
            tmp.ed=t.ed+qu[t.w_id].front().time;
            tmp.w_id=t.w_id;
            tmp.no=qu[t.w_id].front();
            qu[t.w_id].pop();
            q.push(tmp);
            if(k<=K){
                qu[t.w_id].push(nd[k++]);
            }

        }else{
            if(m==1){
                if(k<=K){
                    que tmp;
                    tmp.ed=t.ed+nd[k].time;
                    tmp.w_id=t.w_id;
                    tmp.no=nd[k];
                    q.push(tmp);
                    k++;
                }
            }else{
                que tmp;
                tmp.ed=MAXX;
                tmp.w_id=t.w_id;
                q.push(tmp);
            }
        }
    }
    //for(int i=1;i<=K;i++)
    //    cout<<records[i]<<" ";
    //cout<<endl;
    for(int i=1;i<=Q;i++){
        if(records[query[i]]==-1||records[query[i]]-nd[query[i]].time>=9*60){
            cout<<"Sorry";
        }else{
            printf("%02d:%02d",8+records[query[i]]/60,records[query[i]]%60);
        }
        if(i!=Q) cout<<endl;
    }
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值