zoukankan      html  css  js  c++  java
  • HDU-1873-看病要排队

    题目链接

    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 ");
    else
    {
    printf("%d ",doctor1.top().key);
    doctor1.pop();
    }
    }
    else if(doctorid==2)
    {
    if(doctor2.empty())
    printf("EMPTY ");
    else
    {
    printf("%d ",doctor2.top().key);
    doctor2.pop();
    }
    }
    else
    {
    if(doctor3.empty())
    printf("EMPTY ");
    else
    {
    printf("%d ",doctor3.top().key);;
    doctor3.pop();
    }
    }
    }
    }
    }
    return 0;
    }

  • 相关阅读:
    install kde in ubuntu
    Upgrade to or Install Cinnamon 2.4 in Ubuntu
    enjoy dollar vs cash dollar
    opencv linux
    高频交易都有哪些著名的算法
    wpf
    opencv mat flags含义
    gphoto2 canon eos450d
    gphoto2
    task optimization之superglue分析
  • 原文地址:https://www.cnblogs.com/liudehao/p/4022386.html
Copyright © 2011-2022 走看看