2018牛客多校训练----Singing Contest(模拟+STL)

链接:https://www.nowcoder.com/acm/contest/144/A
来源:牛客网
 

题目描述

Jigglypuff is holding a singing contest. There are 2n singers indexed from 1 to 2n participating in the contest.

The rule of this contest is like the knockout match. That is, in the first round, singer 1 competes with singer 2, singer 3 competes with singer 4 and so on; in the second round, the winner of singer 1 and singer 2 competes with the winner of singer 3 and singer 4 and so on. There are n rounds in total.

Each singer has prepared n songs before the contest. Each song has a unique pleasantness. In each round, a singer should sing a song among the songs he prepared. In order not to disappoint the audience, one song cannot be performed more than once. The singer who sings the song with higher pleasantness wins.

Now all the singers know the pleasantness of songs prepared by all the others. Everyone wants to win as many rounds as he can. Assuming that singers choose their song optimally, Jigglypuff wants to know which singer will win the contest?

输入描述:

The input starts with one line containing exactly one integer t which is the number of test cases. (1 ≤ t ≤ 10)

For each test case, the first line contains exactly one integer n where 2n is the number of singers. (1 ≤ n ≤ 14)

Each of the next 2n lines contains n integers where aij is the pleasantness of the j-th song of the i-th singer. It is guaranteed that all these 2nx n integers are pairwise distinct. (1 ≤ aij ≤ 109)

输出描述:

For each test case, output "Case #x: y" in one line (without quotes), where x is the test case number (starting from 1) and y is the index of the winner.

 

示例1

输入

2
1
1
2
2
1 8
2 7
3 4
5 6

输出

Case #1: 2
Case #2: 4

  共2的n次方的选手,每个选手准备了n首歌,每一首歌有对应的分数,每首歌的分数互不相同。相邻的选手两两比较,演唱一首歌的分数高的选手晋级下一轮,最终获胜的选手是谁。每个选手都尽最大努力赢。

 思路:

  模拟一下比赛的淘汰过程。

#include<bits/stdc++.h>
using namespace std;
 
const int N=1e5+100;
 
multiset<int>s[N];
multiset<int>::iterator it1,it2;
int a[N];
 
int main()
{
    int T,cas=1;
    scanf("%d",&T);
    while(T--)
    {
        int n,m,i,j;
        scanf("%d",&n);
        //m=(1<<n);
        m=pow(2,n);
        for(i=1;i<=m;i++)
        {
            a[i]=i;
            s[i].clear();
            for(j=1;j<=n;j++)
            {
                int x;
                scanf("%d",&x);
                s[i].insert(x);
            }
        }
        for(i=1;i<=n;i++,m/=2)
        {
            for(j=1;j<=m;j+=2)
            {
                it1=s[a[j]].end();
                it2=s[a[j+1]].end();
                it1--,it2--;
                if(*it1>*it2)
                {
                    s[a[j]].erase(s[a[j]].lower_bound(*it2));
                    a[(j+1)/2]=a[j];
                }
                else
                {
                    s[a[j+1]].erase(s[a[j+1]].lower_bound(*it1));
                    a[(j+1)/2]=a[j+1];
                }
            }
        }
        printf("Case #%d: %d\n",cas++,a[1]);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值