SDNU 1506.D.Swiss-system tournament(并列排序)
Posted rootvount
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SDNU 1506.D.Swiss-system tournament(并列排序)相关的知识,希望对你有一定的参考价值。
Description
A Swiss-system tournament is a tournament which uses a non-elimination format. The first tournament of this type was a chess tournament in Zurich in 1895, hence the name "Swiss system". The tournament will be held based on following rules.
2*N contestants (indexed 1, 2, ..., 2*N) will have R rounds matches. Before the first round, every contestant has an origin score. After every match, winner will get 1 score and loser will get 0 score. Before and after every round, contestants will be sorted by their scores in descending order. Two contestants with the same score will be sorted by their index with ascending order.
In every round, contestants will have match based on the sorted list. The first place versus the second place, the third place versus the forth place, ..., the Kth place versus the (K + 1)th place, ..., the (2*N - 1)th place versus (2*N)th place.
Now given the origin score and the ability of every contestant, we want to know the index of the Qth place contestant. We ensured that there won’t be two contestants with the same ability and the contestant with higher ability will always win the match.
Input
Multiple test cases. The first line contains a positive integer T (T<=10) indicating the number of test cases.
For each test case, the first line contains three positive integers N (N <= 100,000), R (R <= 50), Q (Q <= 2*N), separated by space.
The second line contains 2*N non-negative integers, s1, s2, ..., s2*N, si (si<= 100000000) indicates the origin score of constant indexed i.
The third line contains 2*N positive integers, a1, a2, ..., a2*N, ai (ai<= 100000000) indicates the ability of constant indexed i.
Output
One line per case, an integer indicates the index of the Qth place contestant after R round matches.
Sample Input
1 2 4 2 7 6 6 7 10 5 20 15
Sample Output
1
Hint
Versus |
Scores after round |
||||
Index |
/ |
①(10) |
②(5) |
③(20) |
④(15) |
Origin |
/ |
7 |
6 |
6 |
7 |
Round 1 |
① VS ④ ②VS ③ |
7 |
6 |
7 |
8 |
Round 2 |
④ VS ① ③VS ② |
7 |
6 |
8 |
9 |
Round 3 |
④ VS ③ ①VS ② |
8 |
6 |
9 |
9 |
Round 4 |
③ VS ④ ①VS ② |
9 |
6 |
10 |
9 |
思路:这道题用单纯的结构体排序绝对会T,要用并列排序才可以。
/// /// _ooOoo_ /// o8888888o /// 88" . "88 /// (| -_- |) /// O\ = /O /// ____/`---‘\____ /// .‘ \\| |// `. /// / \\||| : |||// /// / _||||| -:- |||||- /// | | \\\ - /// | | /// | \_| ‘‘\---/‘‘ | | /// \ .-\__ `-` ___/-. / /// ___`. .‘ /--.--\ `. . __ /// ."" ‘< `.___\_<|>_/___.‘ >‘"". /// | | : `- \`.;`\ _ /`;.`/ - ` : | | /// \ \ `-. \_ __\ /__ _/ .-` / / /// ======`-.____`-.___\_____/___.-`____.-‘====== /// `=---=‘ /// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ /// Buddha Bless, No Bug ! /// #include <cstdio> #include <iostream> #include <string> #include <cstring> #include <cmath> #include <algorithm> #include <queue> #include <vector> #include <map> using namespace std; #define ll long long const int mod = 1e9+7; struct man int index, score, ability; v[200000+8], en[200000+8]; int t, n, r, q; bool cmp(man a, man b) if(a.score != b.score)return a.score>b.score; return a.index<b.index; int main() for(scanf("%d", &t); t--; ) scanf("%d%d%d", &n, &r, &q); for(int i = 0; i<2*n; i++) scanf("%d", &v[i].score); v[i].index = i+1; for(int i = 0; i<2*n; i++) scanf("%d", &v[i].ability); sort(v, v+2*n, cmp); for(int i = 0; i<r; i++) int la = 0, ra = n; for(int j = 0; j<n; j++) if(v[2*j].ability<v[2*j+1].ability) v[2*j+1].score++; en[la++] = v[2*j+1]; en[ra++] = v[2*j]; else v[2*j].score++; en[la++] = v[2*j]; en[ra++] = v[2*j+1]; // for(int i = 0; i<2*n; i++) // cout<<en[i].score<<" "; // cout<<endl; int lb = 0, rb = n, sign = 0; while(lb<la && rb<ra) if(en[lb].score == en[rb].score) if(en[lb].index<en[rb].index) v[sign++] = en[lb++]; else v[sign++] = en[rb++]; else if(en[lb].score<en[rb].score)v[sign++] = en[rb++]; else if(en[lb].score>en[rb].score)v[sign++] = en[lb++]; while(lb<la)v[sign++] = en[lb++];///如果rb已经排序完成,还剩下lb没排序完成,那就是lb剩余的都小于rb之前的元素,此时直接把lb的元素直接加上去 while(rb<ra)v[sign++] = en[rb++];///如果lb已经排序完成,还剩下rb没排序完成,那就是rb剩余的都小于lb之前的元素,此时直接把rb的元素直接加上去 // cout<<endl; printf("%d\n", v[q-1].index); return 0;
以上是关于SDNU 1506.D.Swiss-system tournament(并列排序)的主要内容,如果未能解决你的问题,请参考以下文章