比赛的时候虽然考虑到没门的情况,但是写了几组都能过,就没想了,23333,差一行代码就能A,遗憾~~
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map> 8 using namespace std; 9 #define MOD 1000000007 10 #define pb(a) push_back(a) 11 const int INF=0x3f3f3f3f; 12 const double eps=1e-5; 13 typedef long long ll; 14 #define cl(a) memset(a,0,sizeof(a)) 15 #define ts printf("***** "); 16 const int MAXN=150010; 17 int n,m,tt,cnt,k; 18 struct Node 19 { 20 int id; 21 char s[205]; 22 int v; 23 friend bool operator<(Node a,Node b) 24 { 25 if(a.v==b.v) 26 { 27 return a.id>b.id; 28 } 29 return a.v<b.v; 30 } 31 }node[MAXN]; 32 struct Node2 33 { 34 int b,c; 35 void in() 36 { 37 scanf("%d%d",&b,&c); 38 } 39 }node2[MAXN]; 40 int ans[MAXN]; 41 void fun() 42 { 43 int i; 44 priority_queue<Node> q; 45 Node now; 46 int sum=0,tot=0; 47 for(i=1;i<=k;i++) 48 { 49 q.push(node[i]); 50 if(q.size()+sum==node2[tot].b) 51 { 52 for(int j=0;j<node2[tot].c&&!q.empty();j++) 53 { 54 now=q.top(); 55 q.pop(); 56 ans[sum++]=now.id; 57 } 58 tot++; 59 } 60 } 61 while(!q.empty()) 62 { 63 now=q.top(); 64 q.pop(); 65 ans[sum++]=now.id; 66 } 67 } 68 bool cmp(Node2 aa,Node2 bb) 69 { 70 return aa.b<bb.b; 71 } 72 int main() 73 { 74 int i,j,ca=1,q; 75 #ifndef ONLINE_JUDGE 76 freopen("1.in","r",stdin); 77 #endif 78 scanf("%d",&tt); 79 while(tt--) 80 { 81 scanf("%d%d%d",&k,&m,&q); 82 83 for(i=1;i<=k;i++) 84 { 85 scanf("%s%d",&node[i].s,&node[i].v); 86 node[i].id=i; 87 } 88 node2[0].b=-1; 89 for(i=0;i<m;i++) 90 { 91 node2[i].in(); 92 } 93 sort(node2,node2+m,cmp); 94 fun(); 95 int qq; 96 for(i=0;i<q;i++) 97 { 98 scanf("%d",&qq); 99 qq--; 100 if(i==0) 101 { 102 printf("%s",node[ans[qq]].s); 103 continue; 104 } 105 printf(" %s",node[ans[qq]].s); 106 } 107 printf(" "); 108 } 109 110 }