二叉树应用题——迷阵的出口

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

//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;
} 

在这里插入图片描述

Guess you like

Origin blog.csdn.net/PanDaoxi2020/article/details/121728858