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 ...
随机推荐
- wepy 小程序定时器(验证码倒计时) 数据绑定页面无刷新
每次改变数据的时候记得调用 this.$apply() 验证码倒计时 使用的vant-weapp UI组件 wxml: <van-col span="10" style= ...
- UVA 11552 序列划分模型 状态设计DP
这个题目刚看到还真不好下手,把一个是 k的倍数的长度的字符串分成len/k块,每块是k个字母,每个块可以重新组合,最后使得整个序列的相同字母尽量在一起,也就是说,最后会把序列从前往后扫,相连的相同字母 ...
- PHP的一个小tips (关于=和==或者===的使用)
由于我在项目中,很多场景判断等式成立的时候 都习惯把值放在==前面(例如 1 == $nStatus), 今天有个同事揪着我问为啥总这样写,回答之后今天也稍作记录下吧. 如果正常些 $nStatus ...
- Restful设计相关
1.get,从服务器获取资源. 2.post 新增资源. 3.put 更新完整资源. 4.patch 更新部分资源. 5. delete 删除资源.
- 客户主题分析(tableau)—客户留存
客户留存分析(客户漏斗分析),关键在于找到影响客户留存的因素,设计场景测试,验证关键因素.即可以通过关键因素影响留存,从而重塑客户漏斗到更有价值的形状. 案例:母婴产品客户留存分析 数据结构: 1) ...
- 中小规模集群----Centos6部署wordpress及java程序
1 概述 1.1 业务需求 公司共有两个业务,网上图书馆和一个电商网站.现要求运维设计一个安全架构,本着高可用.廉价的原则. 具体情况如下: 网上图书馆是基于jsp开发: 电商系统是基于 ...
- 完整注册登陆php源码,附带session验证。
1.首先先写表单页面login.html. <!DOCTYPE html> <html lang="en"> <head> <me ...
- one_day_one_linuxCmd---scp命令
<坚持每天学习一个 linux 命令,今天我们来学习 scp 命令> scp 命令主要用在不同的 linux 系统之间 copy 文件,基于 ssh 登录,是一种安全的复制 scp 命令的 ...
- 洛谷 P1082 同余方程(exgcd)
题目传送门 解题思路: 因为推导过程过于复杂,懒得写,所以题解传送门 AC代码: #include<iostream> #include<cstdio> using names ...
- sql字符串常用函数
1.replace REPLACE(String,from_str,to_str) 即:将String中所有出现的from_str替换为to_str 2.left left(String,2) 从 ...