标签:
Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2650 Accepted Submission(s): 722
#include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<cstdio> #include<queue> #include<vector> #include<cstdlib> #include<string> #include<map> #include<stack> using namespace std; #define ll long long #define lson le,mid,num<<1 #define rson mid+1,ri,num<<1|1 #define stop1 puts("QAQ") #define stop2 system("pause") #define maxn 160000 struct node { char s[203]; int val; int id; bool operator < (const node & a) const { if(val!=a.val) return val < a.val; return id>a.id; } }peo[maxn]; struct kk { int x,y; }tt[maxn]; int cmp(kk a, kk b) { return a.x < b.x; } char ans[maxn][203]; int main() { int T; scanf("%d",&T); while(T--) { int k,m,q; scanf("%d%d%d",&k,&m,&q); for(int i=1;i<=k;i++) { scanf("%s%d",peo[i].s,&peo[i].val); peo[i].id=i; } for(int i=1;i<=m;++i) scanf("%d%d",&tt[i].x,&tt[i].y); sort(tt+1, tt+m+1,cmp); priority_queue<node> Q; memset(ans, 0, sizeof ans); int sum=0,pos=1; for(int i=1;i<=m;i++) { for(int j = pos; j <=tt[i].x; j++) { Q.push(peo[j]); pos++; } for(int j=1;j<=tt[i].y;j++) { if(!Q.empty()) {node temp = Q.top(); Q.pop(); sum++; strcpy(ans[sum],temp.s); } else break; } } for(int i=pos;i<=k;i++) { Q.push(peo[i]); } while(!Q.empty()) { node temp = Q.top(); Q.pop(); sum++; strcpy(ans[sum],temp.s); } int ss; for(int i=1;i<q;i++) { scanf("%d",&ss); printf("%s ",ans[ss]); } if(q!=0) { scanf("%d",&ss); printf("%s\n",ans[ss]); } } return 0; }
HDU5437 Alisha’s Party (优先队列 + 模拟)
标签:
原文地址:http://www.cnblogs.com/ZP-Better/p/4817302.html