标签:
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5877 Accepted Submission(s): 2417
1 #include <queue> 2 #include <cstdio> 3 #include <cstring> 4 #include <stdio.h> 5 using namespace std; 6 7 struct patients 8 { 9 int want, pri, id; 10 friend bool operator < (patients want, patients pri) 11 { 12 if(want.pri == pri.pri) 13 return want.id > pri.id; 14 else 15 return want.pri < pri.pri; //**数越大, 优先级越大*s* 16 } 17 }; 18 19 int main() 20 { 21 int n; 22 while(~scanf("%d", &n)) 23 { 24 priority_queue <patients> doctor1; //三个医生, 定义三个队列; 25 priority_queue <patients> doctor2; 26 priority_queue <patients> doctor3; 27 int ans=0, a, b; 28 char ko[10]; 29 patients t; 30 while(n--) 31 { 32 scanf("%s", ko); 33 if(ko[0] == ‘I‘) 34 { 35 scanf("%d %d", &a, &b); 36 ++ans; 37 if(a == 1) //入队 ; 38 { 39 t.want = a; 40 t.pri = b; 41 t.id = ans; 42 doctor1.push(t); 43 } 44 if(a == 2) 45 { 46 t.want = a; t.pri = b; t.id = ans; 47 doctor2.push(t); 48 } 49 if(a == 3) 50 { 51 t.want = a; t.pri = b; t.id = ans; 52 doctor3.push(t); 53 } 54 } 55 else 56 { 57 int find; 58 scanf("%d", &find); //出队; 59 if(find == 1) 60 { 61 if(!doctor1.empty()) 62 { 63 t=doctor1.top(); 64 doctor1.pop(); 65 printf("%d\n",t.id); 66 } 67 else 68 printf("EMPTY\n"); 69 } 70 if(find == 2) 71 { 72 if(!doctor2.empty()) 73 { 74 t=doctor2.top(); doctor2.pop(); 75 printf("%d\n",t.id); 76 } 77 else 78 printf("EMPTY\n"); 79 } 80 if(find == 3) 81 { 82 if(!doctor3.empty()) 83 { 84 t=doctor3.top(); doctor3.pop(); 85 printf("%d\n",t.id); 86 } 87 else 88 printf("EMPTY\n"); 89 } 90 } 91 } 92 } 93 return 0; 94 }
标签:
原文地址:http://www.cnblogs.com/fengshun/p/4682995.html