牛客网暑期ACM多校训练营(第六场)A(Singing Contest)

题目描述 
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.

输入

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

Case #1: 2
Case #2: 4

题意:给出n,有2^n个人参加比赛,比赛n轮,每次只有相邻的两人对战,如刚开始(1,2),(3,4)...(2^n-1,2^n)。其中每个人有n首歌曲,每首歌曲只能唱一次,每首歌有个权值,两人对战权值高的获胜,每个人都想尽可能的获胜且进行更多轮,问最后冠军是谁。

思路:暴力模拟,用一个set模拟

代码:

set <int> s[1<<maxn];
int now[1<<maxn];
int n;
int main(){
    int T,cas=0;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n); cas++;
        for(int i=1;i<=(1<<n);i++){
            s[i].clear(); now[i]=i;
            for(int j=1;j<=n;j++){
                int x;
                scanf("%d",&x);
                s[i].insert(x);
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=(1<<n);j+=(1<<i)){
                set<int>::iterator a=s[now[j]].end(); a--;
                set<int>::iterator b=s[now[j+(1<<(i-1))]].end(); b--;
                set<int>::iterator x,y;
                x=s[now[j]].lower_bound(*b); y=s[now[j+(1<<(i-1))]].lower_bound(*a);
                if((*a)>(*b)){
                    s[now[j]].erase(x);
                }
                else{
                    s[now[j+(1<<(i-1))]].erase(y);
                    now[j]=now[j+(1<<(i-1))];
                }
            }
        }
        printf("Case #%d: %d\n",cas,now[1]);
    }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值