标签:
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5795 Accepted Submission(s):
2384
/* * 利用优先队列来将最大的优先权的患者 * 输出 * 不太会用优先队列参考了别人代码 * 还写得不简洁 惭愧 * */ #include<stdio.h> #include<string.h> #include<algorithm> #include<queue> using namespace std; struct node1 { int time1; int pat1; friend bool operator < (node1 a,node1 b) { if(a.pat1!=b.pat1) return a.pat1<b.pat1; else return a.time1>b.time1; } }; struct node2 { int time2; int pat2; friend bool operator < (node2 a,node2 b) { if(a.pat2!=b.pat2) return a.pat2<b.pat2; else return a.time2>b.time2; } }; struct node3 { int time3; int pat3; friend bool operator < (node3 a,node3 b) { if(a.pat3!=b.pat3) return a.pat3<b.pat3; else return a.time3>b.time3; } }; int main() { int n,m,t,k,a; char s1[10]; char str1[5]={"IN"}; while(scanf("%d",&t)!=EOF) { priority_queue<node1>q1;//医生1的看病情况 priority_queue<node2>q2;//医生2 priority_queue<node3>q3;//医生3 node1 x1;//定义结构体名 node2 x2; node3 x3; k=1; while(t--) { scanf("%s",s1); if(s1[0]==‘I‘) { scanf("%d%d",&n,&m); if(n==1) { x1.time1=k; x1.pat1=m; q1.push(x1); } else if(n==2) { x2.time2=k; x2.pat2=m; q2.push(x2); } else if(n==3) { x3.time3=k; x3.pat3=m; q3.push(x3); } k++; } else { scanf("%d",&a); if(a==1) { if(q1.empty()) printf("EMPTY\n"); else { x1=q1.top(); printf("%d\n",x1.time1); q1.pop(); } } else if(a==2) { if(q2.empty()) printf("EMPTY\n"); else { x2=q2.top(); printf("%d\n",x2.time2); q2.pop(); } } else if(a==3) { if(q3.empty()) printf("EMPTY\n"); else { x3=q3.top(); printf("%d\n",x3.time3); q3.pop(); } } } } } return 0; }
标签:
原文地址:http://www.cnblogs.com/tonghao/p/4681166.html