1 5 2 3 Sorey 3 Rose 3 Maltran 3 Lailah 5 Mikleo 6 1 1 4 2http://write.blog.csdn.net/postedit 1 2 3
Sorey Lailah Rose
优先队列+模拟,en,应该还行,时间上应该不会超时了,但是下面问题来了。。。
真的是无力吐槽了,感觉。。。
因为排序的问题,一直错,一直错,一直错,结果拖累的小组最后这个题都没A掉。。。
#include<iostream> #include<stdio.h> #include<math.h> #include <string> #include<string.h> #include<map> #include<queue> #include<set> #include<utility> #include<vector> #include<algorithm> #include<stdlib.h> using namespace std; #define eps 1e-8 #define pii pair<int,int> #define INF 0x3f3f3f3f #define rd(x) scanf("%d",&x) #define rd2(x,y) scanf("%d%d",&x,&y) #define ll long long int char outname[150005][205]; int coun=0; struct People { char name[205]; int value; int pre; friend bool operator < (People n1, People n2) { if(n1.value != n2.value) return n1.value < n2.value; return n1.pre > n2.pre; } } people[150005]; int main () { //cout<<"&&&"<<endl; int Case; rd(Case); while(Case--) { int now=0; coun=0; int n,innum,quenum; rd(n); rd2(innum,quenum); for(int i=0; i<n; i++) { scanf("%s",&people[i].name); rd(people[i].value); people[i].pre = i; } priority_queue <People> que; int temp1,temp2; <span style="background-color: rgb(153, 255, 153);"> for(int i=0; i<innum; i++) { rd2(temp1,temp2); for(int i=now; i<temp1; i++) que.push(people[i]);//查push和push_back区别 now=temp1; temp2 = (temp2>que.size() ? que.size() : temp2); for(int i=0; i<temp2 ; i++) { strcpy(outname[coun++],que.top().name); que.pop(); } }</span> int quearr[150005],tempmax=-1; for(int i=0; i<quenum; i++) { rd(quearr[i]); if(tempmax<quearr[i]) tempmax=quearr[i]; } if( tempmax > coun+1 ) { for(int i=now; i<n ; i++) que.push(people[i]); } while(!que.empty()) { strcpy(outname[coun++],que.top().name); que.pop(); } for(int i=0; i<quenum; i++) { printf("%s",outname[ quearr[i]-1 ]); if(i<quenum-1) printf(" "); } printf("\n"); } return 0 ; }
#include<iostream> #include<stdio.h> #include<math.h> #include <string> #include<string.h> #include<map> #include<queue> #include<set> #include<utility> #include<vector> #include<algorithm> #include<stdlib.h> using namespace std; #define eps 1e-8 #define pii pair<int,int> #define INF 0x3f3f3f3f #define rd(x) scanf("%d",&x) #define rd2(x,y) scanf("%d%d",&x,&y) #define ll long long int char outname[150005][205]; int coun=0; struct T{ int a,b; }a[150005]; bool cmp(T x,T y){ return x.a<y.a; } struct People { char name[205]; int value; int pre; friend bool operator < (People n1, People n2) { if(n1.value != n2.value) return n1.value < n2.value; return n1.pre > n2.pre; } } people[150005]; int main () { //cout<<"&&&"<<endl; int Case; rd(Case); while(Case--) { int now=0; coun=0; int n,innum,quenum; rd(n); rd2(innum,quenum); for(int i=0; i<n; i++) { scanf("%s",&people[i].name); rd(people[i].value); people[i].pre = i; } priority_queue <People> que; int temp1,temp2; for(int i=0; i<innum ;i++) rd2(a[i].a,a[i].b); sort(a,a+innum,cmp); for(int i=0; i<innum; i++) { temp1=a[i].a,temp2=a[i].b; for(int i=now; i<temp1; i++) que.push(people[i]);//查push和push_back区别 now=temp1; //temp2 = (temp2>que.size() ? que.size() : temp2); for(int i=0; i<temp2 ; i++) { if(que.empty()) break; strcpy(outname[coun++],que.top().name); que.pop(); } } int quearr[150005],tempmax=-1; for(int i=0; i<quenum; i++) { rd(quearr[i]); // if(tempmax<quearr[i]) tempmax=quearr[i]; } //if( tempmax > coun+1 ) // { for(int i=now; i<n ; i++) que.push(people[i]); // } while(!que.empty()) { strcpy(outname[coun++],que.top().name); que.pop(); } for(int i=0; i<quenum; i++) { printf("%s",outname[ quearr[i]-1 ]); if(i<quenum-1) printf(" "); } printf("\n"); } return 0 ; }
。。。good code。。。
#pragma comment(linker, "/STACK:102400000,102400000") #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #include <queue> #include <map> #include <vector> #include <algorithm> #include <conio.h> #include <iostream> using namespace std; #define rd(x) scanf("%d",&x) #define rd2(x,y) scanf("%d%d",&x,&y) #define ll long long int #define maxn 100005 #define mod 1000000007 #define pii pair<int,int> #define maxn 150005 int n,m,t,q,x,y; struct node { int k,v; friend bool operator <(node a,node b) { if(a.v==b.v) return a.k>b.k; return a.v<b.v; } }; char s[maxn][205]; int v[maxn]; int ans[maxn]; int ti[maxn],tot,qq[200]; int main() { rd(t); getchar(); while(t--) { rd2(n,m); getchar(); rd(q); getchar(); for(int i=1; i<=n; i++) { scanf("%s%d",s[i],&v[i]); } memset(ti,0,sizeof(ti)); for(int i=1; i<=m; i++) { scanf("%d%d",&x,&y); ti[x]=y; } tot=0; int mt=0; for(int i=1; i<=q; i++) { rd(qq[i]); mt=mt>qq[i]?mt:qq[i]; } priority_queue<node> que; node nn; int k; for(int i=1; i<=n; i++) { nn.k=i; nn.v=v[i]; que.push(nn); if(i==n) { while(!que.empty()) { nn=que.top(); que.pop(); ans[++tot]=nn.k; if(tot>=mt) break; } break; } for(int j=1; j<=ti[i]; j++) { if(que.empty()) break; nn=que.top(); que.pop(); ans[++tot]=nn.k; } if(tot>=mt) break; } for(int i=1; i<=q; i++) { printf("%s",s[ans[qq[i]]]); if(i==q) printf("\n"); else printf(" "); } } return 0; }