HDU-1873-看病要排隊

來源:互聯網
上載者:User

標籤:http   io   os   ar   sp   代碼   amp   ef   bs   

題目連結

http://acm.hdu.edu.cn/showproblem.php?pid=1873

優先隊列,設定三個priority——queue 

分別存doctor1 doctor2 doctor3;

代碼

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;

struct Patient
{
int priority;
int key;
friend bool operator <(Patient p1,Patient p2)
{
if(p1.priority!=p2.priority)
return p1.priority<p2.priority;

return p1.key>p2.key;
}
};


int main(void)
{
int i,n,k;
char type[4];
int patientid,doctorid;
Patient patient[2001];
while(scanf("%d",&n)==1)
{
priority_queue<Patient> doctor1;
priority_queue<Patient> doctor2;
priority_queue<Patient> doctor3;
k=1;
while(n--)
{
scanf("%s",type);
if(strcmp(type,"IN")==0)
{
patient[k].key=k;
scanf("%d%d",&doctorid,&patient[k].priority);
if(doctorid==1)
{
doctor1.push(patient[k]);
}
else if(doctorid==2)
{
doctor2.push(patient[k]);
}
else
{
doctor3.push(patient[k]);
}
k++;
}
else if(strcmp(type,"OUT")==0)
{
scanf("%d",&doctorid);
if(doctorid==1)
{
if(doctor1.empty())
printf("EMPTY\n");
else
{
printf("%d\n",doctor1.top().key);
doctor1.pop();
}
}
else if(doctorid==2)
{
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 0;
}

HDU-1873-看病要排隊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.