题意:给n个医生,这些医生有一个上班时间,然后给一些病人,病人有一个到达的时间,以及一些诊断,诊断有property(优先级)和duration(诊断时间)这两个属性,每个病人可能要诊断多次,最后问每个病人的全部疗程完成离开医院的时间是多少。

分析:用优先队列存储诊断,病人,然后模拟一个诊断过程,完成病人的个数等于病人数的时候就结束。具体看代码吧。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdlib>
using namespace std;
#define N 100102
#define M 22 struct treat
{
int tim,ind;
treat(int _tim,int _ind):tim(_tim),ind(_ind){}
treat(){}
bool operator <(const treat& a)const
{
return tim > a.tim;
}
}; struct node
{
int x,y;
node(int _x,int _y):x(_x),y(_y){}
node(){}
}; struct Patient
{
int id,pro,arrtim;
Patient(int _id,int _pro,int _arrtim):id(_id),pro(_pro),arrtim(_arrtim){}
Patient(){}
bool operator <(const Patient& a)const
{
if(a.pro == pro)
return arrtim > a.arrtim;
return pro < a.pro;
}
}; priority_queue<treat> T;
priority_queue<Patient> P;
vector<node> pat[],ans;
int arrive[],treated[]; int cmp(node ka,node kb)
{
if(ka.x == kb.x)
return ka.y < kb.y;
return ka.x < kb.x;
} int main()
{
int n,Tim,a,b,Pcnt,cs = ;
int i,j;
while(scanf("%d%d",&n,&Tim)!=EOF && (n+Tim))
{
Pcnt = ;
ans.clear();
while(scanf("%d",&arrive[Pcnt]) && arrive[Pcnt] != -)
{
pat[Pcnt].clear();
while(scanf("%d%d",&a,&b) && (a+b)) //property,duration
pat[Pcnt].push_back(node(a,b));
Pcnt++;
}
while(!T.empty())
T.pop();
while(!P.empty())
P.pop();
for(i=;i<n;i++) //n个医生准备
T.push(treat(Tim,-));
for(i=;i<Pcnt;i++)
T.push(treat(arrive[i],i)); //编号i
int doctor = ;
memset(treated,-,sizeof(treated));
int pcnt = ;
while(pcnt < Pcnt)
{
int nowt = T.top().tim;
while(!T.empty() && T.top().tim == nowt)
{
if(T.top().ind == -) //空闲doctor
doctor++;
else
{
int pid = T.top().ind;
treated[pid]++;
if(treated[pid] >= pat[pid].size()) //全部疗程完成
{
ans.push_back(node(nowt,arrive[pid]));
pcnt++;
}
else
P.push(Patient(pid,pat[pid][treated[pid]].x,arrive[pid]));
}
T.pop();
}
while(!P.empty() && doctor)
{
int k = P.top().id;
T.push(treat(nowt+pat[k][treated[k]].y,-)); //此时空闲
T.push(treat(nowt+pat[k][treated[k]].y,k)); //或者继续诊断此病人
P.pop();
doctor--;
}
}
sort(ans.begin(),ans.end(),cmp);
printf("Case %d:\n",cs++);
for(i=;i<ans.size();i++)
printf("Patient %d released at clock = %d\n",ans[i].y,ans[i].x);
}
return ;
}

UVALive 6093 Emergency Room --优先队列实现的模拟的更多相关文章

  1. Northwestern European Regional Contest 2016 NWERC ,F题Free Weights(优先队列+Map标记+模拟)

    传送门: Vjudge:https://vjudge.net/problem/Gym-101170F CF: http://codeforces.com/gym/101170 The city of ...

  2. UVALive 5888 Stack Machine Executor (栈+模拟)

    Stack Machine Executor 题目链接: http://acm.hust.edu.cn/vjudge/problem/26636 Description http://7xjob4.c ...

  3. UVALive 3486/zoj 2615 Cells(栈模拟dfs)

    这道题在LA是挂掉了,不过还好,zoj上也有这道题. 题意:好大一颗树,询问父子关系..考虑最坏的情况,30w层,2000w个点,询问100w次,貌似连dfs一遍都会TLE. 安心啦,这肯定是一道正常 ...

  4. UVALive 2323 Modular Multiplication of Polynomials(模拟)

    这是一个相对简单的模拟,因为运算规则已经告诉了我们,并且比较简单,不要被吓到…… 思路:多项式除以另外一个多项式,如果能除,那么他的最高次一定被降低了,如果最高次不能被降低,那说明已经无法被除,就是题 ...

  5. UVALive 3135--Argus+自己定义优先队列的优先规则

    题目链接:id=18684">点击进入 仅仅是题意比較难懂,读懂题后全然能够用优先队列水过去.这次学会自己定义优先队列的优先规则,事实上就是在结构体中重载一下<运算符. 代码例如 ...

  6. uva11997 K Smallest Sums&&UVALive 3135 Argus(优先队列,多路归并)

    #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...

  7. UVaLive 4254 Processor (二分+优先队列)

    题意:有n个任务,每个任务有三个参数,r,d,w,表示该任务必须在[r,d]之间执行,工作量是w,处理器执行速度可以变化,当执行速度是s的时候, 一个工作量是w的任务需要需要的执行时间是w/s个工作单 ...

  8. Luogu P2278 [HNOI2003]操作系统【优先队列/重载运算符/模拟】 By cellur925

    题目传送门 本来是照着二叉堆的题去做的...没想到捡了个模拟...不过模拟我都不会...我好弱啊... 其实核心代码并不长,比辰哥的标程短到不知哪里去...但是思路需要清晰. 读题的时候我明白,当有优 ...

  9. UVaLive 6802 Turtle Graphics (水题,模拟)

    题意:给定一个坐标,和一行命令,按照命令走,问你有多少点会被访问超过一次. 析:很简单么,按命令模拟就好,注意有的点可能走了多次,只能记作一次. 代码如下: #pragma comment(linke ...

随机推荐

  1. log4j.xml 配置参数属性level使用心得

    jdbc.sqlonly        只显示执行的sql语句.info级才可以显示,debug增加显示java源代码位置. jdbc.sqltiming    显示执行的sql语句以及语句执行时间, ...

  2. SharePoint 自定义WebPart之间的连接

    1.创建SharePoint解决方案,添加两个WebPart分别用来发送和接收: 2.发送值的WebPart需要继承自IWebPartField(当然,根据需要还可以选择IWebPartField,I ...

  3. [leetcode] Contains Duplicate II

    Contains Duplicate II Given an array of integers and an integer k, find out whether there there are ...

  4. CSS 指定选择器(十一)

    一.指定选择器 有时个会希望控制某个元素在一定范围内的对象样式,这时就可以把元素与Class或者Id选择器结合起来使用 <!DOCTYPE html PUBLIC "-//W3C//D ...

  5. 更轻量的 View Controllers

    iew controllers 通常是 iOS 项目中最大的文件,并且它们包含了许多不必要的代码.所以 View controllers 中的代码几乎总是复用率最低的.我们将会看到给 view con ...

  6. Android之 左右滑动菜单

    近来学习了极客学院有关于界面左右滑动的视频,就在这里写个博客,巩固一下知识点,以免忘了. 这里主要介绍界面是如何左右滑动的: 1.首先我们应该设置好将要滑动的三个界面,即leftMenu.middle ...

  7. Android多进程需要注意的一个地方

    可能很多项目都会有一个自定义的Application,做一些初始化操作以及全局化的一些数据保存,这时如果程序中定义了远程服务(android:process=":remote"), ...

  8. 数据库性能优化之SQL语句优化

    一.问题的提出 在应用系统开发初期,由于开发数据库数据比较少,对于查询SQL语句,复杂视图的编写等是体会不出SQL语句各种写法的性能优劣,但是如果将应用系统提交实际应用后,随着数据库中数据的增加,系统 ...

  9. Oracle查看所有用户

    1.查看所有用户:select * from dba_users;   select * from all_users;   select * from user_users; 2.查看用户或角色系统 ...

  10. JavaScript Patterns 4.1 Functions Background

    Functions are first-class objects and they provide scope. • Can be created dynamically at runtime, d ...