UVA 10588—— Queuing at the doctors
生活随笔
收集整理的這篇文章主要介紹了
UVA 10588—— Queuing at the doctors
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題意:給定n個(gè)工人和m個(gè)醫(yī)生,然后進(jìn)行體檢,每個(gè)醫(yī)生每秒接待一個(gè)工人,每個(gè)人都有一個(gè)體檢項(xiàng)目順序和時(shí)間,問最后一個(gè)員工完成體檢的時(shí)間。
思路:優(yōu)先隊(duì)列模擬,建立m個(gè)項(xiàng)目的優(yōu)先隊(duì)列,當(dāng)某個(gè)工人滿足體檢時(shí)間時(shí),給該工人體檢,然后push到下一個(gè)項(xiàng)目中去。
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());} }創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)
總結(jié)
以上是生活随笔為你收集整理的UVA 10588—— Queuing at the doctors的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: dnf2012盛世狂欢和神圣的守护者哪个
- 下一篇: 成都大熊猫繁育研究基地用不用预约