zoukankan      html  css  js  c++  java
  • 牛客多校对抗第6场 A Singing Contest

    【20分】标题:A、Singing Contest | 时间限制:1秒 | 内存限制:256M
    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首歌,每首歌都有一个愉悦值,1号和2号pk,3号和4号pk,。。。and so on,每个歌手已经知道对方每首的愉悦值,愉悦值大的歌会淘汰愉悦值小的歌,求哪位歌手最终可以获胜
    题解:每首歌用了后就不能用,但是要打败目前的对手,那么我们将歌的愉悦值排序,谁最大的愉悦值小谁就out了,但是愉悦值大的歌手不能浪费他最大愉悦值的那首歌,找到尽可能小的获胜歌手的一首歌去out掉他的对手就行,把愉悦值大的尽可能留到后面

    代码如下:
    #include <map>
    #include <set>
    #include <cmath>
    #include <ctime>
    #include <stack>
    #include <queue>
    #include <cstdio>
    #include <cctype>
    #include <bitset>
    #include <string>
    #include <vector>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #include <functional>
    #define fuck(x) cout<<"["<<x<<"]";
    #define FIN freopen("input.txt","r",stdin);
    #define FOUT freopen("output.txt","w+",stdout);
    //#pragma comment(linker, "/STACK:102400000,102400000")
    using namespace std;
    typedef long long LL;
    typedef pair<int, int> PII;
    const int maxn = 2e4+5;
    int n;
    queue<LL> q;
    vector<LL> v[maxn];
    void init(){
        for(int i=0;i<maxn;i++){
            v[i].clear();
        }
        while(!q.empty()){
            q.pop();
        }
    
    
    }
    bool cmp(long long  a,long long  b){
        return a>b;
    }
    int main(){
    #ifndef ONLINE_JUDGE
        FIN
    #endif
        int T;
        scanf("%d",&T);
        int cas=1;
        while(T--){
            init();
            scanf("%d",&n);
            int m=pow(2,n);
            for(int i=0;i<m;i++){
                for(int j=0;j<n;j++){
                    LL t;
                    scanf("%lld",&t);
                    v[i].push_back(t);
                }
                sort(v[i].begin(), v[i].end(),cmp);
                q.push(i);
            }
            printf("Case #%d: ",cas++);
            while(q.size()>1){
                int t1,t2;
                t1=q.front();q.pop();
                t2=q.front();q.pop();
                if(v[t1][0]<v[t2][0]){
                    swap(t1,t2);
                }
                q.push(t1);
                vector<LL>::iterator it;
                int i=0;
                for(it=v[t1].begin();it!=v[t1].end();it++){
                    if(i==n-1){
                        v[t1].erase(v[t1].begin()+i);
                        break;
                    }
                    if(v[t1][i]>v[t2][0]&&v[t1][i+1]<v[t2][0]){
                        v[t1].erase(v[t1].begin()+i);
                        break;
                    }
                    i++;
                }
    
            }
            printf("%d
    ",q.front()+1);
        }
    }
    View Code







    每一个不曾刷题的日子 都是对生命的辜负 从弱小到强大,需要一段时间的沉淀,就是现在了 ~buerdepepeqi
  • 相关阅读:
    Django之ORM基础
    Django基本命令
    Django知识总汇
    Linux Shell 自动化之让文本飞
    伪类link,hover,active,visited,focus的区别
    小记 Linux 之 Vim
    恢复 MSSQL bak 文件扩展名数据(上)
    小记一次shellscript的麻烦
    Java 之多态
    Java 之封装
  • 原文地址:https://www.cnblogs.com/buerdepepeqi/p/9418868.html
Copyright © 2011-2022 走看看