hdu1873-看病要排队-(结构体优先队列)
2024-09-07 20:23:54
http://acm.hdu.edu.cn/showproblem.php?pid=1873
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<set>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std; struct patient
{
int id;
int val;
}; patient p[]; bool operator<(patient p1,patient p2)
{
if(p1.val==p2.val)
return p1.id>p2.id;
return p1.val<p2.val;
}
///优先级高的排在前面,重载操作符出来效果和自定义函数相反
priority_queue<patient>que1,que2,que3; int n;
string s;
int a,b; int main()
{
while(cin>>n)
{
while(que1.size())
que1.pop();
while(que2.size())
que2.pop();
while(que3.size())
que3.pop();
int cnt=;
while(n--)
{
cin>>s;
if( s[]=='I' )
{
cin>>a>>b;///有一个优先级为b的病人要a医生诊治
cnt++;
if( a== )///丢进a医生得队列
que1.push({cnt,b});
if(a==)
que2.push({cnt,b});
if(a==)
que3.push({cnt,b});
}
else
{
cin>>a;///医生a诊断了一个病人,问此人编号,即队列出队
patient now;
if(a==)
{
if(que1.size())
{
now=que1.top();
que1.pop();
cout<<now.id<<endl;
}
else
cout<<"EMPTY"<<endl;
}
else if(a==)
{
if(que2.size())
{
now=que2.top();
que2.pop();
cout<<now.id<<endl;
}
else
cout<<"EMPTY"<<endl;
}
else
{
if(que3.size())
{
now=que3.top();
que3.pop();
cout<<now.id<<endl;
}
else
cout<<"EMPTY"<<endl;
}
} }
}
return ;
}
最新文章
- java并发编程系列
- HTML5的学习--performance
- Scrum敏捷项目管理精要
- Python OpenCV —— Arithmetic
- 编写高质量代码改善C#程序的157个建议[协变和逆变]
- audio.js – 随时随地,播放 HTML5 的声音
- ICursor查询后的排序问题
- 《HTML5与CSS3基础教程》学习笔记 ——Two Day
- 【java基础】--(3)javaIO详细阐释
- Object -C self -- 笔记
- Window.open 实现导航与打开窗口,导航到一个特定链接地址,也可以打开一个新的浏览器窗体
- Eclipse使用git 上传代码至github
- 关于Resharper的使用经验
- Android自定义底部带有动画的Dialog
- 第七周LINUX学习笔记
- 第三周 数据分析之概要 Pandas库数据特征分析
- Python中的算数运算
- RabbitMQ 死信队列 延时
- C++ leetcode Longest Substring Without Repeating Characters
- 2018/04/07 每日一个Linux命令 之 logrotate
热门文章
- 微信小程序绑定列表数据
- springboot kafka生产者
- Windwos Server 2016 远程桌面授权
- Java连载15-boolean类型&;类型转换&;++运算符
- SpringBoot第十八篇:异步任务
- Maven 教程(22)— Maven中 plugins 和 pluginManagement
- 适配器模式(Adapter Pattern)--设计模式
- Redis(四)Pub/Sub
- DOM的回流和重绘(重排、重绘)
- 【java】javac命令在win10不可用,提示javac不是内部或外部命令,也不是可运行的程序【解决方法】