来源:点击打开链接

看路径记录的BFS之前,再看一遍优先队列的用法。

优先队列的排序规则可以用运算符重载的方式完成,通常意义下,应该用friend bool operator <进行重载。

#include <iostream>
#include <cstring>
#include <queue>
#include <string>
using namespace std; class hospital
{
public:
int level;
int id;
friend bool operator < (hospital c1,hospital c2)
{
if(c1.level!=c2.level)
return c1.level<c2.level;
else
return c1.id>c2.id;
}
}; int main()
{
int testcase;
while(cin>>testcase)
{
int doc,level;
int as=0;
string op;
priority_queue<hospital> p[4];
hospital tmp;
while(testcase--)
{
cin>>op;
if(op=="IN")
{
as++;
cin>>doc>>level;
tmp.level=level;
tmp.id=as;
//cout<<"idis"<<tmp.id<<endl;
p[doc].push(tmp); }
else if(op=="OUT")
{
cin>>doc;
if(p[doc].empty())
cout<<"EMPTY"<<endl;
else
{
tmp=p[doc].top();
p[doc].pop();
cout<<tmp.id<<endl; }
}
} }
return 0;
}

【优先队列】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 Submission(s) ...

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

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

  4. hdu 1873 看病要排队(优先级队列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1873 题目大意: 三个医生看病,病人排队看病,病人有优先级,优先级高的提前看病,同样的优先级按先后.I ...

  5. hdu 1509 & hdu 1873 & hdu 1896 (基础优先队列)

    http://acm.hdu.edu.cn/showproblem.php?pid=1509 裸的优先队列的应用,输入PUT的时候输入名字,值和优先值进队列,输入GRT的时候输出优先值小的名字和对应的 ...

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

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

  7. hdu——1873(优先队列)

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

  8. hdu acm 2082 找单词

    找单词 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  9. HDU 2086 A1 = ? (找规律推导公式 + 水题)(Java版)

    Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2086 ——每天在线,欢迎留言谈论. 题目大意: 有如下方程:Ai = (Ai-1 ...

随机推荐

  1. java&c# dec 加密,通用

    java /** * 解密DES * @param key 密钥,长度必须是8的倍数 * @param data 数据源 * @return 解密内容 */ public final static S ...

  2. Supports BorlandIDEServices

    Delphi: procedure SetKeystrokeDebugging(Debugging: Boolean); var Dialog: IOTAKeyboardDiagnostics beg ...

  3. 【转】Java中只有按值传递,没有按引用传递!

    原文链接:http://guhanjie.iteye.com/blog/1683637 今天,我在一本面试书上看到了关于java的一个参数传递的问题: 写道 java中对象作为参数传递给一个方法,到底 ...

  4. C++11静态assert

    [C++11静态assert] C++11新的关键字static_assert可以解决模板中的状态检察. 声明采取以下的形式: 这里有一些如何使用static_assert的例子: 当常数表达式值为f ...

  5. POJ 1039 Pipe(直线和线段相交判断,求交点)

    Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8280   Accepted: 2483 Description ...

  6. codeforces 601A The Two Routes(最短路 flody)

    A. The Two Routes time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. C++视频课程小结(2)

    C++远征之离港篇 章节介绍: 每章小结: 第一章:大致讲了一下本章会讲的内容:引用vs指针.const vs #define(这个我在C里都没用过).函数变得更强大.内存管理要小心之类的. 第二章: ...

  8. window 方法:延时 和 重复

    window 方法 var timer = setTimeout(closeFunc,10*1000); function closeFunc(){ alert('close'); }

  9. 编译安装-MySQL5.5

    一.参数选项 1.目录选项 2.存储引擎选项 3.库文件加载选项 二.安装 1.环境准备 2.安装前的系统设置 3.安装执行 4.初始化数据库 5.注册为服务 6.加入环境变量 7.启动服务 8.重新 ...

  10. 网站在域名前面添加logo小图标

    如何给界面添加logo?就像百度的首页出现的图标. 1.准备一个ICO格式的小图标. 2.将制作好的ICO文件放到tomcat下的“D:\apache-tomcat-6.0.16\webapps\RO ...