社区讨论

TLE on #5 求调

P1305新二叉树参与者 2已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@m6pxyzd4
此快照首次捕获于
2025/02/04 11:50
去年
此快照最后确认于
2025/11/04 10:01
4 个月前
查看原帖
CPP
#include<iostream>
#include<map>
using namespace std;
int n;
char tree[30];
map<char, int> Index;
void front(int node) {
	if (tree[node] == '*') {
		return;
	}
	cout << tree[node];
	front(node * 2);
	front(node * 2 + 1);
}
int main() {
	cin >> n;
	char node, LeftChild, RightChild;
	cin >> node >> LeftChild >> RightChild;
	tree[1] = node;
	Index[node] = 1;
	tree[2] = LeftChild;
	tree[3] = RightChild;
	Index[LeftChild] = 2;
	Index[RightChild] = 3;
	for (int i = 2; i <= n; i++) {
		cin >> node >> LeftChild >> RightChild;
		tree[Index[node] * 2] = LeftChild;
		tree[Index[node] * 2 + 1] = RightChild;
		Index[LeftChild] = Index[node] * 2;
		Index[RightChild] = Index[node] * 2 + 1;
	}
	front(1);
	return 0;
}

回复

2 条回复,欢迎继续交流。

正在加载回复...