zoukankan      html  css  js  c++  java
  • hdu1873-看病要排队-(结构体优先队列)

    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[2005];
    
    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=0;
            while(n--)
            {
                cin>>s;
                if( s[0]=='I' )
                {
                    cin>>a>>b;///有一个优先级为b的病人要a医生诊治
                    cnt++;
                    if( a==1 )///丢进a医生得队列
                        que1.push({cnt,b});
                    if(a==2)
                        que2.push({cnt,b});
                    if(a==3)
                        que3.push({cnt,b});
                }
                else
                {
                    cin>>a;///医生a诊断了一个病人,问此人编号,即队列出队
                    patient now;
                    if(a==1)
                    {
                        if(que1.size())
                        {
                            now=que1.top();
                            que1.pop();
                            cout<<now.id<<endl;
                        }
                        else
                            cout<<"EMPTY"<<endl;
                    }
                    else if(a==2)
                    {
                        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 0;
    }
  • 相关阅读:
    字符串转换成整型数 atoi()
    求一个正整数各个数位上的数字之和
    求小于等于n的所有素数
    iomanip,setw(),setw: undeclared identifier
    计算机界的牛人前辈
    clrscr( )用法
    printf()
    realloc() 用法详解
    ADO和ADO.NET的区别
    C++中delete和delete[]的区别
  • 原文地址:https://www.cnblogs.com/shoulinniao/p/11372851.html
Copyright © 2011-2022 走看看