//Author:PanDaoxi
#include <iostream>
using namespace std;
bool tree[100001]; //false=black true=white
int main(){
int n,p;//确定层数
cin>>n;
//5种走法
for(int i=1;i<=5;i++){
p=1; //节点编号
for(int j=1;j<n;j++){
if(tree[p]==false){
tree[p]=true; //变色
p*=2; //更改节点状态
}
else{
tree[p]=false;
p=p*2+1;
}
}
cout<<p<<" ";
}
return 0;
}
二叉树应用题——迷阵的出口
原创
©著作权归作者所有:来自51CTO博客作者PanDaoxi的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:C++树状结构(第二弹)
下一篇:C++二叉树叶子结点的个数
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
【数据结构】二叉树的存储结构
【数据结构】第五章——树与二叉树详细介绍二叉树的存储结构……
二叉树 数据结构 C语言 -
二叉树应用题——迷阵的出口
二叉树应用题——迷阵的出口
c++ 二叉树 #include ios i++ -
二叉树应用题——推算后序遍历序列
二叉树应用题——推算后序遍历序列
c++ 链表 数据结构 #include 中序 -
【二叉树】合并二叉树
题目给定两个二叉树想象当你将它们中的一个 覆盖 到另一个上时两个二叉树的一些节点便
swift 深度优先 算法 ios objective-c -
对称二叉树【二叉树】
时间复杂度:空间复杂度:
python 复杂度 Code 空间复杂度 -
【二叉树】二叉树的坡度
给定一个二叉树,计算整个树的`坡度`一个树的 `节点的坡度` 定义为,该节点 `左` 子树的节点之`和` 与 `右`
深度优先 算法 swift ios objective-c -
【二叉树】重建二叉树
题目输入某二叉树的前序遍历和中序遍历的结果请构建该二叉树并返回其根节点假设
swift 算法 二叉树 中序遍历 子树 -
【二叉树】验证二叉树
题目二叉树上有 n 个节点,按从 0 到 n - 1 编号其中节点 i 的两个子节点分别是 leftChild[i]
swift 二叉树 算法 子节点 数组 -
【二叉树】平衡二叉树
题目给你一个二叉树判断它是否是高度平衡的二叉树一棵高度平衡二叉树定义为:一
swift 算法 开发语言 ios objective-c -
二叉树刷题总结:二叉树的遍历方式
二叉树的遍历方式分为俩种,一种是深度优先遍历也就是我们常说的 DFS
算法 后端 二叉树 前序遍历 后序遍历