UVA 10588—— Queuing at the doctors

来源:互联网 发布:古生物学就业 知乎 编辑:程序博客网 时间:2024/06/16 21:16

题意:给定n个工人和m个医生,然后进行体检,每个医生每秒接待一个工人,每个人都有一个体检项目顺序和时间,问最后一个员工完成体检的时间。


思路:优先队列模拟,建立m个项目的优先队列,当某个工人满足体检时间时,给该工人体检,然后push到下一个项目中去。


code:

#include <bits/stdc++.h>using namespace std;const int N=1005;int T,n,m;struct node{    int t,id;    bool operator <(const node& B)const {        return t > B.t || (t == B.t && id > B.id);    }}p;priority_queue<node>Q[N];queue<int>q[N];int sol(){    int f = 1, ans = 0;    while (f) {    f = 0;    for (int i = 0; i < m; i++) {        if (!Q[i].empty()) {        f = 1;        node pe = Q[i].top();        if (ans < pe.t) continue;        Q[i].pop();        q[pe.id].pop();        if (!q[pe.id].empty()) {            pe.t = ans + 1;            Q[q[pe.id].front()].push(pe);        }        }    }    ans++;    }    return ans - 1;}int main(){    scanf("%d",&T);    int k,tp;    while (T--){        scanf("%d%d",&n,&m);        for (int i=0;i<n;i++){ p.id=i;        scanf("%d%d",&p.t,&k);        for (int j=0;j<k;j++){            scanf("%d",&tp);            tp--;            q[p.id].push(tp);        }        Q[q[p.id].front()].push(p);        }        //cout<<"bug"<<endl;        printf("%d\n",sol());    }}


0 0