标签:
Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2518 Accepted Submission(s): 681
1 #include<stdio.h> 2 #include<string.h> 3 #include<queue> 4 #define ini(x) while(!x.empty())x.pop() 5 using namespace std; 6 const int MAXN=150010; 7 struct Node{ 8 char s[210]; 9 int w,n; 10 friend bool operator < (Node a,Node b){ 11 if(a.w!=b.w)return a.w<b.w; 12 else return a.n>b.n; 13 } 14 }; 15 priority_queue<Node>dl; 16 queue<Node>as; 17 queue<Node>ae; 18 struct open{ 19 int k,n; 20 friend bool operator < (open a,open b){ 21 return a.k>b.k; 22 } 23 }; 24 priority_queue<open>op; 25 char ans[MAXN][210]; 26 int main(){ 27 int T,k,m,q; 28 scanf("%d",&T); 29 while(T--){ 30 ini(as);ini(ae);ini(op); 31 scanf("%d%d%d",&k,&m,&q); 32 Node a; 33 for(int i=1;i<=k;i++){ 34 scanf("%s%d",a.s,&a.w); 35 a.n=i; 36 as.push(a); 37 } 38 open b; 39 for(int i=1;i<=m;i++){ 40 scanf("%d%d",&b.k,&b.n); 41 op.push(b); 42 }b=op.top(); 43 for(int i=1;i<=k;i++){ 44 a=as.front(); 45 as.pop(); 46 dl.push(a); 47 if(op.empty())continue;//错到这里了 48 if(i==b.k){ 49 int t=0; 50 while(t++<b.n){ 51 if(dl.empty())break; 52 a=dl.top(); 53 dl.pop(); 54 ae.push(a); 55 } 56 op.pop();b=op.top(); 57 } 58 } 59 while(!dl.empty()){ 60 a=dl.top(); 61 dl.pop(); 62 ae.push(a); 63 } 64 int k=1; 65 while(!ae.empty()){ 66 a=ae.front();ae.pop(); 67 strcpy(ans[k++],a.s); 68 } 69 int x; 70 for(int i=0;i<q;i++){ 71 scanf("%d",&x); 72 if(i)printf(" "); 73 printf("%s",ans[x]); 74 } 75 puts(""); 76 } 77 return 0; 78 }
代码二:
1 #include<stdio.h> 2 #include<string.h> 3 #include<queue> 4 #include<algorithm> 5 #define ini(x) while(!x.empty())x.pop() 6 using namespace std; 7 const int MAXN=150010; 8 struct Node{ 9 char s[210]; 10 int w,n; 11 friend bool operator < (Node a,Node b){ 12 if(a.w!=b.w)return a.w<b.w; 13 else return a.n>b.n; 14 } 15 }; 16 priority_queue<Node>dl; 17 Node as[MAXN]; 18 queue<Node>ae; 19 struct open{ 20 int k,n; 21 }; 22 open op[MAXN]; 23 int cmp(open a,open b){ 24 if(a.k!=b.k)return a.k<b.k; 25 else return a.n>b.n; 26 } 27 char ans[MAXN][210]; 28 int main(){ 29 int T,k,m,q; 30 scanf("%d",&T); 31 while(T--){ 32 ini(ae);ini(dl); 33 scanf("%d%d%d",&k,&m,&q); 34 Node a; 35 for(int i=1;i<=k;i++){ 36 scanf("%s%d",a.s,&a.w); 37 a.n=i; 38 as[i]=a; 39 } 40 open b; 41 for(int i=1;i<=m;i++){ 42 scanf("%d%d",&b.k,&b.n); 43 op[i]=b; 44 } 45 sort(op+1,op+m+1,cmp); 46 for(int i=1,j=1;i<=k;i++){ 47 a=as[i]; 48 dl.push(a); 49 if(j>m)continue;//错到这里了 50 if(i==op[j].k){ 51 int t=0; 52 while(t++<op[j].n){ 53 if(dl.empty())break; 54 a=dl.top(); 55 dl.pop(); 56 ae.push(a); 57 } 58 j++; 59 } 60 } 61 while(!dl.empty()){ 62 a=dl.top(); 63 dl.pop(); 64 ae.push(a); 65 } 66 int k=1; 67 while(!ae.empty()){ 68 a=ae.front();ae.pop(); 69 strcpy(ans[k++],a.s); 70 } 71 int x; 72 for(int i=0;i<q;i++){ 73 scanf("%d",&x); 74 if(i)printf(" "); 75 printf("%s",ans[x]); 76 } 77 puts(""); 78 } 79 return 0; 80 }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4833309.html