The seventh session of Shandong Province Swiss-system D tournament (merge sort)

Source: Internet
Author: User

Test instructions

Give 2n player ID, ability value and initial score

Then by the scores from big to small, id from small to large sort

The next player plays

Score +1 with a high capacity value

Carry R Wheel

Q What is the number of the player ID after the game?

Ideas:

Start with sort once, each round of the game is merged

Win a group of people, lose a group of people, to ensure that two groups of orderly

Then merge into the original array

The output will be good after the R wheel.

/************************************************author:d evilcreated TIME:2016/6/10 14:24:16***************** ******************************* */#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<cmath>#include<stdlib.h>using namespacestd;Const intn=1e5+Ten;intN;structwq{intId,score,cap; voidPushintAintBintc) {ID=A; Score=b; Cap=C; }}eg[n<<1],eg1[n],eg2[n];BOOLCMP (Wq a,wq b) {if(A.score!=b.score)returnA.score>B.score; returna.id<b.id;}voidFun () {intl1=1, l2=1;  for(intI=1; i<=n;i+=2)    {        if(eg[i].cap>eg[i+1].cap| | eg[i].cap==eg[i+1].cap&&eg[i].id<eg[i+1].id) {eg1[l1++].push (eg[i].id,eg[i].score+1, Eg[i].cap); Eg2[l2++]=eg[i+1]; }        Else{EG1[L1++].push (eg[i+1].id,eg[i+1].score+1, eg[i+1].cap); Eg2[l2++]=Eg[i]; }    }    intA=1, b=1, c=1;  while(a<l1&&b<L2) {        if(eg1[a].score>eg2[b].score| | eg1[a].score==eg2[b].score&&eg1[a].id<eg2[b].id) Eg[c++]=eg1[a++]; Elseeg[c++]=eg2[b++]; }     while(A&LT;L1) eg[c++]=eg1[a++];  while(B&LT;L2) eg[c++]=eg2[b++];}intMain () {//freopen ("In.txt", "R", stdin);    intt,r,q; scanf ("%d",&t);  while(t--) {scanf ("%d%d%d",&n,&r,&q); N<<=1;  for(intI=1; i<=n;i++) {scanf ("%d",&Eg[i].score); Eg[i].id=i; }         for(intI=1; i<=n;i++) scanf ("%d",&eg[i].cap); Sort (eg+1, eg+n+1, CMP);  while(r--) fun (); printf ("%d\n", eg[q].id); }    return 0;}

The seventh session of Shandong Province Swiss-system D tournament (merge sort)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.