1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| #include<iostream> #include<cstdio> #include<algorithm> using namespace std; int num,round,inquiry,score[200005],power[200005],No[200005],winner[100005],loser[100005];
bool cmp(int, int); void mergesort(); void compete(); int main() { cin>>num>>round>>inquiry; for(int i=1;i<=2*num;i++) cin>>score[i]; for(int i=1;i<=2*num;i++) cin>>power[i]; for(int i=1;i<=2*num;i++) No[i]=i;
sort(No+1,No+1+2*num,cmp);
for(int i=1;i<=round;i++) { compete(); mergesort(); }
cout<<No[inquiry]; return 0;
} bool cmp(int m, int n) { if(score[m]==score[n]) return m<n; else return score[m]>score[n]; }
void compete() { for(int i=1;i<=2*num;i=i+2) { if(power[No[i]]>power[No[i+1]]) { score[No[i]]++; winner[i/2+1]=No[i]; loser[i/2+1]=No[i+1]; } else if(power[No[i]]<power[No[i+1]]) { score[No[i+1]]++; winner[i/2+1]=No[i+1]; loser[i/2+1]=No[i]; } }
}
void mergesort() {
int i=1,j=1; while(i<=num && j<=num) { if(cmp(winner[i],loser[j])) { No[i+j-1]=winner[i]; i++; } else { No[i+j-1]=loser[j]; j++; }
}
while(i<=num) { No[i+num]=winner[i]; i++; } while(j<=num) { No[j+num]=loser[j]; j++; }
}
|