求调
  • 板块学术版
  • 楼主lucy2012
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/6/1 15:59
  • 上次更新2024/6/1 18:21:50
查看原帖
求调
1252442
lucy2012楼主2024/6/1 15:59

T112246

high函数好像出了问题。

#include<bits/stdc++.h>
using namespace std;
int n,pos=0;
char tree[1000010];
string s;
void buildtree(int r){
	tree[r]=s[pos++];
	if(tree[r]!='#'){
		buildtree(2*r);
		buildtree(2*r+1);
	}
}
void inorder(int r){
	if(tree[r]=='#')
	    return;
	inorder(r*2);
	cout<<tree[r];
	inorder(r*2+1);
}
void beorder(int r){
	if(tree[r]=='#')
	    return;
	beorder(r*2);
	beorder(r*2+1);
	cout<<tree[r];
}
int leaf(int r){
	if(tree[r]=='#')
	    return 0;
	if(tree[r*2]=='#'&&tree[r*2+1]=='#')
	    return 1;
	return leaf(r*2)+leaf(r*2+1);
}
int high(int r){
	if(tree[r]=='#')
	    return 0;
	if(tree[r*2]=='#'&&tree[r*2+1]=='#')
	    return 1;
	return max(high(2*r),high(2*r+1)+1);
}
int main(){
	cin>>s;
	n=s.length();
	buildtree(1);
	inorder(1);
	cout<<endl;
	beorder(1);
	cout<<endl;
	cout<<leaf(1)<<endl;
	cout<<high(1)<<endl;
	return 0; 
}
2024/6/1 15:59
加载中...