题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1873

题目大意:

  三个医生看病,病人排队看病,病人有优先级,优先级高的提前看病,同样的优先级按先后。IN A B : A医生有B病人。OUT  A:A医生看完病人。输入看完病的病人是第几个来的。如果当前的医生没有看病人,输出“EMPYT”.

解题思路:

  三个医生队列(优先队列:可以自动排序,解决了优先级问题),定义一个病人结构体,记录病人的顺序 key 和优先级priority,如果当前病人看1号医生,则当前病人入1号医生的队列,类推。

  输出,如果1号医生输出,则取栈顶元素的key,同时出栈。如果栈顶为空,则输出“EMPTY”.

AC Code:

 #include<bits/stdc++.h>
using namespace std;
struct Patient
{
int priority,key;
friend bool operator < (Patient p1,Patient p2)
{
if(p1.priority != p2.priority)
return p1.priority < p2.priority;
else
return p1.key > p2.key;
}
};
int main()
{
int n,k,doctorId;
Patient patient[];
char type[];
while(scanf("%d",&n)!=EOF)
{
priority_queue<Patient> Doctor1;
priority_queue<Patient> Doctor2;
priority_queue<Patient> Doctor3;
k=;
while(n--)
{
scanf("%s",type);
if(strcmp(type,"IN")==)
{
patient[k].key=k;
scanf("%d %d",&doctorId,&patient[k].priority);
if(doctorId==)
Doctor1.push(patient[k]);
else if(doctorId==)
Doctor2.push(patient[k]);
else Doctor3.push(patient[k]);
k++;
}
else if(strcmp(type,"OUT")==)
{
scanf("%d",&doctorId);
if(doctorId==)
if(Doctor1.empty())printf("EMPTY\n");
else printf("%d\n",Doctor1.top().key),Doctor1.pop();
else if(doctorId==)
if(Doctor2.empty())printf("EMPTY\n");
else printf("%d\n",Doctor2.top().key),Doctor2.pop();
else if(Doctor3.empty())printf("EMPTY\n");
else printf("%d\n",Doctor3.top().key),Doctor3.pop();
}
}
}
return ;
}

hdu 1873 看病要排队(优先级队列)的更多相关文章

  1. hdu 1873 看病要排队

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1873 看病要排队 Description 看病要排队这个是地球人都知道的常识.不过经过细心的0068的 ...

  2. HDU 1873 看病要排队(优先队列)

    看病要排队 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  3. HDU 1873 看病要排队 优先队列

    Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...

  4. hdoj 1873 看病要排队【优先队列】

    看病要排队 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  5. 【优先队列】HDU 1873——看病找医生

    来源:点击打开链接 看路径记录的BFS之前,再看一遍优先队列的用法. 优先队列的排序规则可以用运算符重载的方式完成,通常意义下,应该用friend bool operator <进行重载. #i ...

  6. hdu1873 看病要排队【优先队列】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1873 看病要排队 Time Limit: 3000/1000 MS (Java/Others)     ...

  7. hdu 1872(看病要排队)(优先队列)

    看病要排队 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  8. HDU-1873 看病要排队(队列模拟)

    看病要排队 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  9. HDU 6438"Buy and Resell"(贪心+优先级队列)

    传送门 •参考资料 [1]:HDU6438(优先队列+思维) •题意 有n个城市,第 i 天你会达到第 i 个城市: 在第 i 个城市中,你可以用 ai 元购买一个物品,或者用 ai 元卖掉一个物品, ...

随机推荐

  1. 通过HttpUrlConnection下载文件并显示进度条

    实现效果: 核心下载块: int count = 0; URL url = new URL("http://hezuo.downxunlei.com/xunlei_hezuo/thunder ...

  2. 利用ajaxfileupload.js异步上传文件

    1.引入ajaxfileupload.js 2.html代码 <input type="file" id="enclosure" name="e ...

  3. git之旅【第二篇】

    1,git的安装 最早Git是在Linux上开发的,很长一段时间内,Git也只能在Linux和Unix系统上跑.不过,慢慢地有人把它移植到了Windows上.现在,Git可以在Linux.Unix.M ...

  4. C#-WinForm-Timer控件

    比如在窗体中显示时间: 错误思路一:我在窗体结构函数中写入一个死循环,每隔一秒显示一次当前时间 public Form6() { InitializeComponent(); while (true) ...

  5. C# 时间比较大小

    1.时间比较大小 DateTime   t1   =   new   DateTime(100);     DateTime   t2   =   new   DateTime(20);       ...

  6. 【SPOJ QTREE2】QTREE2 - Query on a tree II(LCA)

    You are given a tree (an undirected acyclic connected graph) with N nodes, and edges numbered 1, 2, ...

  7. Xcode插件VVDocumenter Alcatraz KSImageNamed等安装

    今天安装VVDocumenter,总是不起作用...所以用Alcatraz...下面介绍下Alcatraz 一.Alcatraz Alcatraz 是一款 Xcode的插件管理工具,可以用来管理XCo ...

  8. iOS进度条显示

    一.实现下载文件进度控制 1.代码示例 1 #import "YYViewController.h" 2 3 @interface YYViewController () 4 @p ...

  9. 【BZOJ-1455】罗马游戏 可并堆 (左偏树)

    1455: 罗马游戏 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1355  Solved: 561[Submit][Status][Discuss] ...

  10. 【poj1085】 Triangle War

    http://poj.org/problem?id=1085 (题目链接) 题意 A,B两人玩游戏,在一个大三角形上放火柴,若A放上一根火柴后成功组成一个三角形,那么这个三角形就归属于A,并且A被奖励 ...