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 ...
随机推荐
- C语言的字符串类型
C语言使用指针来管理字符串(1)C语言中定义字符串的方法:char *p = "linux";此时p就叫字符串,但是实际上p只是一个字符指针(本质上就是一个指针变量,只是p指向了一 ...
- 关于 sublime 使用技巧
实行多位置编写 按住 alt 键 用鼠标点击想要编写的位置 实行正方形任意拉选操作 按住 alt 键 用鼠标拖动来进行勾选 继续转发别人的帖子 模块与包的导入 https://blog.csdn ...
- 关于HackerRank的Day 8 的思考——input
Day 8 主要是对字典的一些基本用法做操作. 题干大概是:给定一个 n ,建立一个包含 n 个人的电话簿,然后有一个查询功能.当然,很简单,但是在我对搜索词的输入时,它提示我:EOF when re ...
- Java中Scanner类在nextInt()后无法输入nextLine()的问题
首先,Scanner是一个扫描器,它扫描数据都是去内存中一块缓冲区中进行扫描并读入数据的,而我们在控制台中输入的数据也都是被先存入缓冲区中等待扫描器的扫描读取.这个扫描器在扫描过程中判断停止的依据就是 ...
- 吴裕雄--天生自然 JAVASCRIPT开发学习:测试 jQuery
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Python D9 学习
Python 设置环境 当安装好Python 后 在计算机的属性里面 高级语言设置 环境变量. 环境变量里面的path 更改为Python的 树目录 可以从计算机直接下达命令 打开Pytho ...
- Azure App Service-添加自定义域名和SSL保护
语雀知识库:https://www.yuque.com/seanyu/azure/appservicessl 公众号:云计算实战 案例 添加自定义域并开启SSL保护 进入App Service控制台 ...
- Python说文解字_半成品再加工
1. 其实在编写代码的时候,根据需求和程序员的喜好,对现有类中的属性和方法进行二次加工,原先所给与的属性和方法贴合自己想要的需求.这就是我们常说的“重写”和二次封装. 2. 比如我们对现有的库list ...
- Python基础学习二
Python基础学习二 1.编码 utf-8编码:自动将英文保存为1个字符,中文3个字符.ASCll编码被囊括在内. unicode:将所有字符保存为2给字符,容纳了世界上所有的编码. 2.字符串内置 ...
- CSS3新属性:在网站中使用访客电脑里没有安装的字体
CSS的font-family属性使网页可以使用客户电脑里的字体,从而得到多姿多彩的WEB页面,但当客户端没有你想要使用的字体时怎么办呢?我们总不能让每个访问者都去安装一个字体吧?事实上,这是可以的! ...