zoukankan      html  css  js  c++  java
  • King of the Waves

    You are organising a king of the hill tournament, the Buenos Aires Paddleboarding Competition (BAPC), with n participants. In a king of the hill tournament, one person starts as a “king” and is then challenged by another person, the winning person becomes the new king. This is repeated until all participants have challenged exactly once (except for the starting person). In a paddle- boarding match, there are no draws. The person which ends up as king, wins the tournament. Since you are the organiser, you get to choose the starting person and the order in which they challenge the king.

    Someone is offering you a substantial amount of money in case one of the participants, Henk, ends up winning the tournament. You happen to know, for any two participants x and y, which of the two would win if they were to match during the tournament. Consequently, you choose to do the unethical: you will try to rig the game. Can you find a schedule that makes Henk win the tournament?

    Input

    • The first line contains an integer 1 ≤ n ≤ 1000, the number of participants. The participants are numbered 0, . . . , n − 1, where Henk is 0.
    • Then n lines follow, where each line has exactly n characters (not counting the newline character). These lines represent the matrix with the information of who beats who, as follows. On line i the jth character is (note that 0 ≤ i, j < n):
      • '1' if person i will win against person j.
      • '0' if person i will lose against person j.
      • 'X' if i = j.

    Output

    Print a sequence of participants, such that the first person starts as king and the consequent participants challenge the king. If there is no way to rig the game such that Henk wins, print "impossible".

    本题答案不唯一,符合要求的答案均正确

    #include <bits/stdc++.h>
    
    using namespace std;
    bool mapp[2000][2000],visit[2000],flag;
    int match[2000],n,t;
    void dfs(int u)
    {
       if(t==n-1){
           flag=true;
           return;
       }
       else{
           for(int v=0;v<n;v++){
            if(mapp[u][v]&&!visit[v]){
                visit[v]=true;
                match[t++]=v;
                dfs(v);
            }
           }
       }
       return;
    }
    
    int main(){
        ios::sync_with_stdio(false);
        char a,b;
        cin>>n;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(i==j) cin>>a;
                else{
                    cin>>b;
                    if(b=='1') mapp[i][j]=true;
                }
            }
        }
        visit[0]=true;
        dfs(0);
        if(!flag) cout<<"impossible"<<endl;
        else{
            for(int i=t-1;i>=0;i--) cout<<match[i]<<" ";
            cout<<0<<endl;
        }
    }
    View Code

    题解:我觉得讲的很明白https://blog.csdn.net/qq_38140099/article/details/79847646

    主要是不一定要谁打败谁

    打不赢也是可以的

    不要忘记努力,不要辜负自己 欢迎指正 QQ:1468580561
  • 相关阅读:
    Angular7 表单
    使用Angular2的Http发送AJAX请求
    Nginx配置SSL证书实现https访问「浏览器未认证」
    详解 Nginx如何配置Web服务器
    前后端分离不可缺少的神器 NGINX
    程序员的快速开发框架:Github上 10 大优秀的开源后台控制面板
    腾讯出品的一个超棒的 Android UI 库
    Vue 旅游网首页开发1-工具安装及码云使用
    Angular routing生成路由和路由的跳转
    Angular 父子组件传值
  • 原文地址:https://www.cnblogs.com/smallocean/p/8747562.html
Copyright © 2011-2022 走看看