题意:给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. SQL数据库基础(三)

    认识数据库备份和事务日志备份 数据库备份与日志备份是数据库维护的日常工作,备份的目的是在于当数据库出现故障或者遭到破坏时可以根据备份的数据库及事务日志文件还原到最近的时间点将损失降到最低点. 数据库备 ...

  2. AngularJS的指令用法

    scope的绑定策略: @ :把当前属性作为字符串传递,你还可以绑定来自外层scope的值,在属性值中插入 {{}}即可 示例代码: scopeAt.html <!doctype html> ...

  3. Javascript面向对象编程(三) --- 非构造函数的继承

    一.什么是"非构造函数"的继承? 比如,现在有一个对象,叫做"中国人". var Chinese = { nation:'中国' }; 还有一个对象,叫做&qu ...

  4. ABAP modify screen:修改屏幕,实现隐藏、禁止输入字段

    Loop at screen会loop处理屏幕上的每一个组件,并对其做相应的处理. SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME.PARAMETERS  ...

  5. How to install and configure Azure PowerShell

    https://azure.microsoft.com/en-us/documentation/articles/powershell-install-configure/ In this artic ...

  6. DevExpress GridControl使用方法总结

    一.如何解决单击记录整行选中的问题 View->OptionsBehavior->EditorShowMode 设置为:Click 二.如何新增一条记录 (1).gridView.AddN ...

  7. Arcgis for android 离线查询

    参考.. 官方API demo ... 各种资料 以及.. ArcGIS for Android示例解析之高亮要素-----HighlightFeatures ttp://blog.csdn.net/ ...

  8. MVC中的CSRF解决方案

    我们使用Ajax访问请求的时候,攻击者可能盗用了用户身份,以用户合法身份发送恶意请求. 具体预防措施, 1.在Html表单里面使用@Html.AntiForgeryToken(),这玩意会生成一对加密 ...

  9. virtualbox迁移至vcenter/vmware workstation

    参考文献: http://www.itsecurenet.com/virtualbox-ova-to-vsphere-ovf/ http://www.techrepublic.com/blog/win ...

  10. Ubuntu 14.04下安装JDK8

    本文地址:http://www.cnblogs.com/archimedes/p/ubuntu-jdk8.html,转载请注明源地址. 欢迎关注我的个人博客:www.wuyudong.com, 更多云 ...