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 ...
随机推荐
- Aras Innovator如何配置SMTP中转Office365
参考文档:http://www.ebdadvisors.com/blog/2015/7/31/configure-an-smtp-server-in-windows-iis-for-aras-inno ...
- 当切换用户时出现-bash-4.1$
问题重现 [root@localhost ~]# su - yh -bash-4.1$ -bash-4.1$ -bash-4.1$ -bash-4.1$ -bash-4.1$ cd /home -ba ...
- 吴裕雄--天生自然 JAVASCRIPT开发学习:Number 对象
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- B - Common Divisors (codeforces)数论算法基本定理,唯一分解定理模板
You are given an array aa consisting of nn integers. Your task is to say the number of such positive ...
- Java中常用的API(四)——其他
前面说三篇文章分别介绍了Object.String.字符缓冲类的API,接下来我们简要介绍一下其他常用的API. 1.System System类用于获取各种系统信息,最为常用的是: System.o ...
- tomcat配置配置文件和war包进行分离
应用部署 war包.配置文件分离 部署主机路径规划以及tomcat中间件改造 1.新建存放war包路径 /appsystems/apps 将war包放置其中 2.新建存放配置文件路径 /apps ...
- HDU 2586 How far away ?【LCA模板题】
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2586 题意:给你N个点,M次询问.1~N-1行输入点与点之间的权值,之后M行输入两个点(a,b)之间的最 ...
- eclipse启动tomcat出现8080,8009,8005端口被占用的问题
有时候我们在eclipse中启动项目时,Tomcat服务器会报错,显示8080.8009.8005这几个端口被占用,此时你用debug启动项目时会发现不管用,console控制台什么信息也没有,此时产 ...
- 使用pyintaller打包python3.6项目,并用c#调用该脚本
一.pythoninstaller 打包python项目 前提:安装python3.6环境+pycharm 1. 安装pyinstaller pip install pyinstaller 2. cm ...
- 题解 LOJ-6485 【LJJ学二项式定理】
题目 由于看到正解的单位根反演过于复杂 (也就是看不懂) 所以自己构造了一个算法,理论上这个算法应该还有成长的空间(可以变得普适性更强) 不知道和单位根反演有没有一样,就发表出来了 反正转载前记得要联 ...