UVALive 6093 Emergency Room --优先队列实现的模拟
题意:给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 --优先队列实现的模拟的更多相关文章
- 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 ...
- UVALive 5888 Stack Machine Executor (栈+模拟)
Stack Machine Executor 题目链接: http://acm.hust.edu.cn/vjudge/problem/26636 Description http://7xjob4.c ...
- UVALive 3486/zoj 2615 Cells(栈模拟dfs)
这道题在LA是挂掉了,不过还好,zoj上也有这道题. 题意:好大一颗树,询问父子关系..考虑最坏的情况,30w层,2000w个点,询问100w次,貌似连dfs一遍都会TLE. 安心啦,这肯定是一道正常 ...
- UVALive 2323 Modular Multiplication of Polynomials(模拟)
这是一个相对简单的模拟,因为运算规则已经告诉了我们,并且比较简单,不要被吓到…… 思路:多项式除以另外一个多项式,如果能除,那么他的最高次一定被降低了,如果最高次不能被降低,那说明已经无法被除,就是题 ...
- UVALive 3135--Argus+自己定义优先队列的优先规则
题目链接:id=18684">点击进入 仅仅是题意比較难懂,读懂题后全然能够用优先队列水过去.这次学会自己定义优先队列的优先规则,事实上就是在结构体中重载一下<运算符. 代码例如 ...
- uva11997 K Smallest Sums&&UVALive 3135 Argus(优先队列,多路归并)
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...
- UVaLive 4254 Processor (二分+优先队列)
题意:有n个任务,每个任务有三个参数,r,d,w,表示该任务必须在[r,d]之间执行,工作量是w,处理器执行速度可以变化,当执行速度是s的时候, 一个工作量是w的任务需要需要的执行时间是w/s个工作单 ...
- Luogu P2278 [HNOI2003]操作系统【优先队列/重载运算符/模拟】 By cellur925
题目传送门 本来是照着二叉堆的题去做的...没想到捡了个模拟...不过模拟我都不会...我好弱啊... 其实核心代码并不长,比辰哥的标程短到不知哪里去...但是思路需要清晰. 读题的时候我明白,当有优 ...
- UVaLive 6802 Turtle Graphics (水题,模拟)
题意:给定一个坐标,和一行命令,按照命令走,问你有多少点会被访问超过一次. 析:很简单么,按命令模拟就好,注意有的点可能走了多次,只能记作一次. 代码如下: #pragma comment(linke ...
随机推荐
- js 当前日期及时间
返回时间格式 : 2016-07-22 10:22:30 function getNowFormatDate() { var date = new Date(); var seperator1 = & ...
- 从网络中获取图片显示到Image控件并保存到磁盘
一.从网络中获取图片信息: /// <summary> /// 获取图片 /// </summary> /// <param name="url"&g ...
- datepicker冲突
公司里的项目由于发展较快,很多东西都没有好好梳理一下,以至于有很多的潜在的问题. 最近就遇到了一个比较坑的问题.datepicker 有两个插件库中的datepicker插件比较有名.一个是jQuer ...
- touch触摸事件
事件对象 事件对象是用来记录一些事件发生时的相关信息的对象.事件对象只有事件发生时才会产生,并且只能是事件处理函数内部访问,在所有事件处理函数运行结束后,事件对象就被销毁! W3C DOM把事件对象作 ...
- 使用Python给要素添加序号
在ArcGIS的属性表中,由于编辑修改的原因,默认的FID或OID并不连续,经常需要给要素添加连读的序号,可使用Python代码完成. rec=-1 def autoIncrement(): glob ...
- Sharepoint学习笔记—习题系列--70-573习题解析 -(Q100-Q103)
Question 100You create a Web Part.You need to display the number of visits to a SharePoint site coll ...
- Android网络编程基础
Android网络编程只TCP通信 TCP 服务器端工作的主要步骤如下.步骤1 调用ServerSocket(int port)创建一个ServerSocket,并绑定到指定端口上.步骤2 调用acc ...
- iOS多线程-03-NSOperation与NSOperationQueue
简介 通过NSOperation与NSOperationQueue的组合也能实现多线程 通常将任务封装成NSOperation对象,并将对象添加到NSOperationQueue中实现 NSOpera ...
- OC语言-01-面向过程与面向对象思想
一.面向过程 1> 思想 面向过程是一种以过程为中心的最基础编程思想,不支持面向对象的特性. 面向过程是一种模块化程序设计方法 2> 开发方法 面向过程的开发方法是以过程(也可以说是模块) ...
- nodeJS创建工程
转http://blog.csdn.net/i348018533/article/details/47258449 设置镜像地址 1.通过config命令 npm config set registr ...