两种自定义优先级写法
View Code
1 #include2 #include 3 #include 4 using namespace std; 5 struct Node 6 { 7 int time; 8 int import; 9 bool operator<(const Node &a) const10 {11 if(a.import>import) return true;12 else if(a.import==import&&a.time
View Code
1 #include2 #include 3 #include 4 #include 5 using namespace std; 6 struct patient 7 { 8 int num;/*编号*/ 9 int imp;/*重要度*/10 }w[1001];11 struct comp12 {13 bool operator()(patient &x,patient &y)/*结构体排序*/14 {15 if(x.imp y.num) return true;17 return false;18 }19 };20 int main()21 {22 int n,i,a,b,count;23 char str[101];24 while(~scanf("%d",&n))25 {26 priority_queue ,comp>doc[4];/*优先队列*/27 count=1;28 while(n--)29 {30 scanf("%s",str);31 if(str[0]=='I')32 {33 scanf("%d %d",&a,&b);34 w[count].num=count;35 w[count].imp=b;36 doc[a].push(w[count]);/*直接插入一个结构体....*/37 count++;38 }39 else40 { 41 scanf("%d",&a);42 if(doc[a].empty())43 {44 printf("EMPTY\n");45 }46 else47 {48 printf("%d\n",doc[a].top().num);49 doc[a].pop();50 }51 }52 }53 }54 return 0;55 }