Hrbust 2311(Swiss-system tournament)归并排序
来源:互联网 发布:科比身体数据 编辑:程序博客网 时间:2024/06/15 22:20
Swiss-system tournament
Time Limit: 2000 MS Memory Limit: 131072 K
Total Submit: 36(6 users) Total Accepted: 7(4 users) Rating: Special Judge: No
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) indicates 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<= 10^8) indicates the origin score of constant indexed i.
The third line contains 2*N positive integers, a1, a2, …, a2*N, ai (ai<= 10^8) 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
题意:给出每个人的编号,分数,和能力值大小,m次比赛,每次按分数优先,编号其次排序。每次比赛相邻两个人比,能力值大的分数加1,再排序。问第m次后 排名为k的人的编号。
题解:模拟肯定是o(nmlogn)。会T。于是想到减少一个log。我们发现,每次比赛,会把人分成两个单调队列(加分的和没加的)。然后就可以归并了。。。
代码:
#include<iostream>#include<stdio.h>#include<stdlib.h>#include<algorithm>#include<vector>#include<cmath>#include<set>#include<string.h>#define ll long longusing namespace std;const int N=1e5+10;struct node{ int id,pi,sore; bool operator <(const node &t)const { return sore>t.sore||(sore==t.sore&&id<t.id); }}a[N<<1],b[N],c[N];int t,n,m,k;void solo(){ int num1=0,num2=0; for(int o=0;o<n;o+=2) { if(a[o].pi>a[o+1].pi) { b[num1]=a[o]; b[num1].sore++; num1++; c[num2++]=a[o+1]; } else { b[num1]=a[o+1]; b[num1].sore++; num1++; c[num2++]=a[o]; } } int i=0,j=0; int num=0; while(i<num1&&j<num2) { if(b[i].sore>c[j].sore||(b[i].sore==c[j].sore&&b[i].id<c[j].id)) a[num++]=b[i++]; else a[num++]=c[j++]; } while(i<num1) a[num++]=b[i++]; while(j<num2) a[num++]=c[j++];}int main(){ scanf("%d",&t); while(t--) { scanf("%d%d%d",&n,&m,&k); n*=2; for(int i=0;i<n;i++) { scanf("%d",&a[i].sore); a[i].id=i+1; } for(int i=0;i<n;i++) { scanf("%d",&a[i].pi); } sort(a,a+n); while(m--) { solo(); } printf("%d\n",a[k-1].id); }}
- Hrbust 2311(Swiss-system tournament)归并排序
- 第七届 山东省ACM Swiss-system tournament(归并思想)
- SDUT 3563 Swiss-system tournament【思维+模拟】
- 第七届ACM山东省赛-D Swiss-system tournament
- 第七届ACM山东省赛-D Swiss-system tournament
- 山东省第七届ACM省赛 Swiss-system tournament
- 瑞士地理坐标系统简介(Swiss Coordinate System or Swiss Grid)
- 排序-归并排序-优化(插入排序+复制采用System.arraycopy)
- hrbust/哈理工oj 1526 小猴和冒泡【归并排序】
- hrbust/哈理工oj 2028 小猴和冒泡2【归并排序】
- Hrbust 2224 逆序对问题【归并排序/离散化树状数组】
- 山东省acm省赛 D题Swiss-system tournetment
- 合并排序(归并)
- 归并排序(ASC)
- 归并排序(C)
- 归并排序(MergeSort)
- 归并排序(上)
- 归并排序(下)
- 汇编中断程序设计
- Nginx学习
- SpringMVC上传图片总结(2)--- 使用百度webuploader上传组件进行上传图片
- C++:组合类
- Eclipse Java注释模板设置详解
- Hrbust 2311(Swiss-system tournament)归并排序
- 用Visio2013画E-R图的步骤
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件(转)
- C++:继承与派生
- UGUI强制新手引导制作方案
- RabbitMQ(五)
- 使用maven创建web项目
- 【MOOC】Python数据分析与展示-北京理工大学-【第〇周】数据分析之前奏
- 配置WAMP的虚拟主机