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-看病要排隊

相關文章

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.