看病要排队

来源:互联网 发布:网络舆情办理 编辑:程序博客网 时间:2024/05/22 10:57

看病要排队

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8069    Accepted Submission(s): 3360


Problem Description
看病要排队这个是地球人都知道的常识。
不过经过细心的0068的观察,他发现了医院里排队还是有讲究的。0068所去的医院有三个医生(汗,这么少)同时看病。而看病的人病情有轻重,所以不能根据简单的先来先服务的原则。所以医院对每种病情规定了10种不同的优先级。级别为10的优先权最高,级别为1的优先权最低。医生在看病时,则会在他的队伍里面选择一个优先权最高的人进行诊治。如果遇到两个优先权一样的病人的话,则选择最早来排队的病人。

现在就请你帮助医院模拟这个看病过程。
 

Input
输入数据包含多组测试,请处理到文件结束。
每组数据第一行有一个正整数N(0<N<2000)表示发生事件的数目。
接下来有N行分别表示发生的事件。
一共有两种事件:
1:"IN A B",表示有一个拥有优先级B的病人要求医生A诊治。(0<A<=3,0<B<=10)
2:"OUT A",表示医生A进行了一次诊治,诊治完毕后,病人出院。(0<A<=3)
 

Output
对于每个"OUT A"事件,请在一行里面输出被诊治人的编号ID。如果该事件时无病人需要诊治,则输出"EMPTY"。
诊治人的编号ID的定义为:在一组测试中,"IN A B"事件发生第K次时,进来的病人ID即为K。从1开始编号。
 

Sample Input
7IN 1 1IN 1 2OUT 1OUT 2IN 2 1OUT 2OUT 12IN 1 1OUT 1
 

Sample Output
2EMPTY311
第一次写超过100行的代码,必须纪念一下。但是这是很笨的方法,又写了一个参照别人的代码。对我提醒最深的就是一定要给栈和队列清空,否则各种wa。
1:
<span style="color:#000000;">#include<cstdio>#include<cstring>#include<queue>#include<stack>#include<algorithm>using namespace std;queue <int> q;queue <int> que;queue <int> qu;struct node{int dj,ts;bool friend operator < (node x,node y){if(x.dj ==y.dj )return x.ts >y.ts ;return x.dj <y.dj;}};int main(){priority_queue <node> q;priority_queue <node> qu;priority_queue <node> que;int n,i,m;struct node lu;char s[5];while(scanf("%d",&n)!=EOF){while(!q.empty())q.pop() ;while(!qu.empty())qu.pop() ;while(!que.empty())que.pop() ;int h=1;for(i=1;i<=n;i++){scanf("%s",s);if(strcmp(s,"IN")==0){scanf("%d%d",&m,&lu.dj);{lu.ts=h++;if(m==1)q.push(lu);else if(m==2)qu.push(lu);elseque.push(lu);}}else{scanf("%d",&m);if(m==1){if(q.empty()){printf("EMPTY\n");continue;}else { lu=q.top();printf("%d\n",lu.ts); q.pop();    }   }   else if(m==2)   {   if(qu.empty()){printf("EMPTY\n");continue;}else {lu=qu.top();printf("%d\n",lu.ts); qu.pop(); }     }   else   {   if(que.empty()){printf("EMPTY\n");continue;}else { lu=que.top();printf("%d\n",lu.ts); que.pop(); }    }   }}  }return 0;}</span>
 
<span style="font-size:24px;color:#000000;">2</span>
<pre class="cpp" name="code"><span style="color:#000000;">#include<cstdio>#include<cstring>#include<queue>#include<stack>#include<algorithm>using namespace std;queue <int> q;struct node{int dj,ts;bool friend operator < (node x,node y){if(x.dj ==y.dj )return x.ts >y.ts ;return x.dj <y.dj;}}a;int main(){int i,n,num,m;char c[10];while(scanf("%d",&n)!=EOF){priority_queue<node> q[4];int h=1;for(i=0;i<n;i++){scanf("%s",c);if(strcmp(c,"IN")==0){scanf("%d%d",&m,&a.dj);a.ts=h++;q[m].push(a); }else{scanf("%d",&m);if(q[m].empty()){printf("EMPTY\n");continue;}else{a=q[m].top() ;printf("%d\n",a.ts );q[m].pop() ;}}}}return 0;}</span>


0 0
原创粉丝点击