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[][],visit[],flag;
int match[],n,t;
void dfs(int u)
{
if(t==n-){
flag=true;
return;
}
else{
for(int v=;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=;i<n;i++){
for(int j=;j<n;j++){
if(i==j) cin>>a;
else{
cin>>b;
if(b=='') mapp[i][j]=true;
}
}
}
visit[]=true;
dfs();
if(!flag) cout<<"impossible"<<endl;
else{
for(int i=t-;i>=;i--) cout<<match[i]<<" ";
cout<<<<endl;
}
}
题解:我觉得讲的很明白https://blog.csdn.net/qq_38140099/article/details/79847646
主要是不一定要谁打败谁
打不赢也是可以的
King of the Waves的更多相关文章
- 2017 Benelux Algorithm Programming Contest (BAPC 17) Solution
A - Amsterdam Distance 题意:极坐标系,给出两个点,求最短距离 思路:只有两种方式,取min 第一种,先走到0点,再走到终点 第二种,走到同一半径,再走过去 #include ...
- gym101666题解
A Amsterdam Distance 题意 求圆环上的两点距离. 分析 显然是沿半径方向走到内圈再走圆弧最短. 代码 #include <bits/stdc++.h> using na ...
- BZOJ 1087: [SCOI2005]互不侵犯King [状压DP]
1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3336 Solved: 1936[Submit][ ...
- Basic EEG waves 四种常见EEG波形
Source: https://www.medicine.mcgill.ca/physio/vlab/biomed_signals/eeg_n.htm The electroencephalogram ...
- [bzoj1087][scoi2005]互不侵犯king
题目大意 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上 左下右上右下八个方向上附近的各一个格子,共8个格子. 思路 首先,搜索可以放弃,因为这是一 ...
- King's Quest —— POJ1904(ZOJ2470)Tarjan缩点
King's Quest Time Limit: 15000MS Memory Limit: 65536K Case Time Limit: 2000MS Description Once upon ...
- 【状压DP】bzoj1087 互不侵犯king
一.题目 Description 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上.下.左.右,以及左上.左下.右上.右下八个方向上附近的各一个格子,共8个格子. I ...
- Waves – 赞!超炫交互体验的点击动画效果
Waves 点击效果的灵感来自于谷歌的材料设计,很容易使用.只需要引入 waves.min.css 和 waves.min.js 到 HTML 文件中可以使用了.采用 touchstart 与 tou ...
- ZOJ 2334 Monkey King
并查集+左偏树.....合并的时候用左偏树,合并结束后吧父结点全部定成树的根节点,保证任意两个猴子都可以通过Find找到最厉害的猴子 Monkey King ...
随机推荐
- nginx log 切割
/logs/nginx/*/*access.log { daily rotate 30 missingok dateext #compress notifempty sharedscripts pos ...
- 2019.9.30极限测试 04.JAVA语言课堂测试试卷-极限测试
题目存储在上传的文件当中. 代码实现 Subway 类: package ClassroomTest; public class Subway { private String railway; pr ...
- Eclipse换DarkestDark主题之后,无法使用快捷键
问题出现: 在选用Eclipse插件的MarketPlace的时候,发现一个下载量很高的主题,看起来很不错,毫不犹豫的就下下来了. 说时迟那时快,下下来之后果然好看,不过问题也来了,快捷键失效了,Ct ...
- c语言:自增自减运算符的操作详解
博主在回忆c语言的基本知识时,突然发现自增自减运算符(--.++)这个知识点有些模糊不清,故博主为了给同为小白的同学们提供一些经验,特写下这篇文章. 首先,自增自减运算符共有两种操作方式. 比如,我先 ...
- main函数的参数(int argc,char *argv[])
一般的main函数都是不带参数的,因此main 后的括号都是空括号.实际上,main函数可以带参数,这个参数可以认为是 main函数的形式参数.C语言规定main函数的参数只能有两个, 习惯上这两个参 ...
- 关于wireshark的使用
1.简介 Wireshark(前称Ethereal)是一个网络封包分析软件.网络封包分析软件的功能是撷取网络封包,并尽可能显示出最为详细的网络封包资料.Wireshark使用WinPCAP作为接口,直 ...
- empty和is_null以及isset函数在0、”0”、‘空串’、NULL、false、array()的计算值
1empty:只要是非空或者非零的值都返回false,换句话说‘’.‘0’.0.null.false都返回true: 2is_null: 当参数满足下面三种情况时,is_null()将返回TRUE,其 ...
- 计蒜客 方程的解数(DFS)
问题描述 输出格式 输出一行,输出一个整数,表示方程的整数解的个数. 样例输入 - 样例输出 #include <stdio.h> #include <string.h> #i ...
- Code Style for OI
Code Style for OI #include #define 尽量少用 #include 能#include <foo>就不#include "foo" #if ...
- JetBrains Phpstorm 、 PyCharm 2019 最新破解码亲测可用
Phpstorm 2019 破解码最新亲测可用 6ZUMD7WWWU-eyJsaWNlbnNlSWQiOiI2WlVNRDdXV1dVIiwibGljZW5zZWVOYW1lIjoiSmV0cyBHc ...