K King of the Waves

2024-02-19 09:32
文章标签 waves king

本文主要是介绍K King of the Waves,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

K King of the Waves

You are organising a king of the hill tournament, the Buenos AiresPaddleboarding Competition (BAPC), with n participants. In aking of the hill tournament, one person starts as a “king” and isthen challenged by another person, the winning person becomesthe new king. This is repeated until all participants have challengedexactly once (except for the starting person). In a paddleboardingmatch, there are no draws. The person which ends up asking, wins the tournament. Since you are the organiser, you get tochoose the starting person and the order in which they challengethe king.

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

Input

• The first line contains an integer 1 ≤ n ≤ 1000, the number of participants. Theparticipants are numbered 0, . . . , n − 1, where Henk is 0.

• Then n lines follow, where each line has exactly n characters (not counting the newlinecharacter). These lines represent the matrix with the information of who beats who, asfollows. 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 consequentparticipants challenge the king. If there is no way to rig the game such that Henk wins, print“impossible”.


     

题意:

给你n,代表有0 n-1个人,给你n行,每行n个字符, 
字符是X,i=j就是这个人在这个位置 
1 代表,i人能赢j人当king 
0代表输; 
游戏规则是b 是king a能赢b a当king 

问裁判按什么安排顺序0能当king

dfs遍历复杂时,可看看题意是否把握好。比如这题,“如何安排顺序使得0能最终获胜”,加入顺序为k1 k2 k3 k4……k1到k2可不是k1指向k2哦!还可以是k2指向k1.(k2 来挑战k1,只不过失败了而已)


思路:

a->b:a能打败b

查找0能打败的,每条支路继续往下搜。

eg:0->2->1->3

     0->4

     0->5->6

不管3、4、6谁能打败谁,0一定能打败它们仨。

代码:

#include<iostream>
#include<cstring>
using namespace std;int n,k,flag;
char s[1005];
int vis[1005];
int a[1005][1005];
int b[1005];void dfs(int h)
{if(k==n-1){flag=1;return;}else{for(int i=0;i<n;i++){if(a[h][i]&&!vis[i]){vis[i]=1;b[k++]=i;dfs(i);}}}
}int main()
{cin>>n;flag=0;k=0;for(int i=0;i<n;i++){cin>>s;for(int j=0;j<n;j++){if(s[j]=='1')a[i][j]=1;elsea[i][j]=0;}}memset(vis,0,sizeof(vis));vis[0]=1;dfs(0);if(flag){for(int i=k-1;i>=0;i--)cout<<b[i]<<" ";cout<<"0"<<endl;}elsecout<<"impossible"<<endl;return 0;
}

这篇关于K King of the Waves的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/724256

相关文章

【POJ】2728 Desert King 最优比率生成树——01分数规划【经典】

最近在刷巨巨们放出来的专题,然后没做几题就卡住了,果然还是太弱了T U T... 这次做到了一题01分数规划求解的生成树问题。 题目大意是这样的:给你一个无向完全图,每条边i都有两个权值,长度a[ i ],花费b[ i ],需要选出其中的一些边构造一颗生成树,生成树需要满足条件:∑ b [ i ] / ∑ a [ i ]最小。 这样我还是先来介绍一下01分数规划吧~ 给定一个上述的问

【HDU】3861 The King’s Problem 强连通缩点+有向图最小路径覆盖

传送门:【HDU】3861 The King’s Problem 题目分析:首先强连通缩点,因为形成一个环的王国肯定在一条路径中,这样才能保证拆的少。 然后缩点后就是DAG图了,由于题目要求的是最小路径覆盖,那么二分匹配即可。 代码如下: #include <cstdio>#include <cstring>#include <algorithm>#includ

【贪心】codeforces30D King‘s problem

直接上中文题面 King's Problem? 时间限制:3.0s  内存限制:256.0MB   Special Judge 问题描述   每一个真正的国王在他的一生中,一定会征服世界,取得 codeforces 的世界冠军,在射击场赢得粉色的熊猫(= =),并游历整个王国。   国王 Copa 已经完成了前三件事。现在他只需要游历完整个王国了。他的王国在一个无限大的笛卡尔坐标系上,每

非常有趣的一道区块连CTF题目的思考————king

区块连CTF题目 区块连CTF题目king 区块连CTF题目前言一、题目以及解答二、题目分析1.进攻receive()函数2.守护king强行selfdestruct转入为什么拿不到king 前言 这道题目在于处理接受函数的知识,另外我们结合selfdestruct函数进行分析 一、题目以及解答 这是一个非常有意思的问题: 首先下面的solidity代码是本次的题

HDU 3861 The King’s Problem

http://acm.hdu.edu.cn/showproblem.php?pid=3861 The King’s Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1828    Accepted Submission

Lesson 73 The way to King Street

Lesson 73 The way to King Street 词汇 week n. 周 = 7 days 相关:weekend 周末    weekday 工作日    weekly adv. 一周一次的    = once a week 例句:一周有七天。    There are seven days in a week. days of the week: Monday 星期一 T

To-King战地日记(之二)

其实我不想告诉大家,在我这篇战地日记之前,我们战队的马姐还有一篇ToKing战地日记,原因是这厮的战地日记让我觉得我头上顶着一个山大的鸭梨。但我还是告诉大家了,为什么呢?因为那篇战地日记介绍了我们战队的每一个成员?因为那是我们战队的第一篇战地日记?还是因为……?其实我只是想让你们知道知道什么是ws。         好吧,说正题。今天我要说的就是我自己前半半(请不要怀疑我多打字了)生的梗概,虽然马

POJ-1904 King's Quest 强连通分量求完美匹配

http://poj.org/problem?id=1904 题目意思:有n个女生和n个男生,给定一些关系表示男生喜欢女生(即两个人可以结婚),再给定一个初始匹配,表示这个男生和哪个女生结婚,初始匹配必定是合法的.求每个男生可以和哪几个女生可以结婚其他人还难能都找个女生结婚。 思路:第一反应还以为是求二分完美匹配,百度题解再知道用连通分量 0.0  将男生从1到n编号,女生从(n+1)到2*n

POJ 1904 King's Quest 强连通分量+二分匹配

好题啊,先赞一个,这里有个讲的好的,感觉让我讲也没他这么好。。。 King's Quest #include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <stack>using namespace std;const int maxn = 2010;vector <int> G[

Codeforces #217 (Div. 2) A Rook, Bishop and King

Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields org