分析:第一次用STL里面的merge
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 #include <vector> 6 #include <algorithm> 7 #include <set> 8 #include <map> 9 #include <bitset> 10 #include <cmath> 11 #include <queue> 12 #include <stack> 13 #include<cctype> 14 using namespace std; 15 const int maxn=200020; 16 typedef struct node{ 17 int start,num,id; 18 }node; 19 node p[maxn],w[maxn],f[maxn]; 20 int n,r,q; 21 inline bool cmp(const node& a,const node& b) 22 { 23 if(a.start==b.start) 24 return a.id<b.id; 25 return a.start>b.start; 26 } 27 int main() 28 { 29 while(cin>>n>>r>>q) 30 { 31 int N=2*n; 32 for(int i=1;i<=N;i++){ 33 scanf("%d",&p[i].start); 34 p[i].id=i; 35 } 36 for(int i=1;i<=N;i++){ 37 scanf("%d",&p[i].num); 38 } 39 sort(p+1,p+1+N,cmp); 40 while(r){ 41 --r; 42 for(int i=1;i<=n;i++){ 43 if(p[i*2].num>p[i*2-1].num){ 44 p[i*2].start++; 45 w[i]=p[i*2]; 46 f[i]=p[i*2-1]; 47 }else{ 48 p[i*2-1].start++; 49 w[i]=p[i*2-1]; 50 f[i]=p[i*2]; 51 } 52 } 53 merge(w+1,w+1+n,f+1,f+1+n,p+1,cmp); 54 } 55 cout<<p[q].id<<endl; 56 } 57 return 0; 58 }