标签:
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Submission(s): 2169 Accepted Submission(s): 672
题解:优先队列;按照题意水一水就好了;
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<queue> using namespace std; const int MAXN = 10010; struct Node{ char nm[21]; int rp; friend bool operator < (Node a,Node b){ if(a.rp != b.rp)return a.rp > b.rp; else { if(strcmp(a.nm,b.nm) < 0)return 1; else return 0; } } }; priority_queue<Node>q[MAXN]; int main(){ int N,M,x; while(~scanf("%d%d",&N,&M)){ Node a; for(int i = 1;i <= N;i++){ while(!q[i].empty())q[i].pop(); scanf("%d",&x); while(x--){ scanf("%s%d",a.nm,&a.rp); q[i].push(a); // printf("***%s\n",q[i].top()); } } // printf("***%s\n",q[1].top()); char s[10]; int xi,xj; while(M--){ scanf("%s",s); if(strcmp(s,"GETON") == 0){ scanf("%d%s%d",&xi,a.nm,&a.rp); q[xi].push(a); } else if(strcmp(s,"JOIN") == 0){ scanf("%d%d",&xi,&xj); while(!q[xj].empty()){ q[xi].push(q[xj].top()); q[xj].pop(); } } else if(strcmp(s,"GETOUT") == 0){ scanf("%d",&xi); printf("%s\n",q[xi].top().nm); q[xi].pop(); } } } return 0; }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/5356155.html