UVA 10588—— Queuing at the doctors
生活随笔
收集整理的這篇文章主要介紹了
UVA 10588—— Queuing at the doctors
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意:給定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());} }創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎
總結
以上是生活随笔為你收集整理的UVA 10588—— Queuing at the doctors的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: dnf2012盛世狂欢和神圣的守护者哪个
- 下一篇: UVA 10410——Tree Reco