两棵不平衡子树AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)You are given a positive integer $N$.
给定一个正整数 $N$。AI (CI翻译)
There is a perfect binary tree with $2^N - 1$ vertices. The vertices are numbered from $1$ to $2^N - 1$.
有一棵包含 $2^N - 1$ 个顶点的完美二叉树。顶点编号为 $1$ 到 $2^N - 1$。AI (CI翻译)
Vertex $1$ is the root, and for each vertex $i$ ($1 \leq i < 2^{N - 1}$), vertex $i$ has vertex $2i$ and vertex $2i + 1$ as its children.
顶点 $1$ 是根。对于每个顶点 $i$($1 \leq i < 2^{N - 1}$),顶点 $i$ 的子节点为顶点 $2i$ 和顶点 $2i + 1$。AI (CI翻译)
Among the ways to write an integer between $1$ and $2^N - 1$, inclusive, on each vertex (where the $2^N - 1$ written integers must be pairwise distinct) such that the following condition is satisfied, find one that minimizes the integer written on vertex $1$.
现在考虑在每个顶点上写入一个介于 $1$ 和 $2^N - 1$(含)之间的整数,且写入的 $2^N - 1$ 个整数必须两两不同,并满足以下条件。在所有满足条件的写法中,找出一种使顶点 $1$ 上写入的整数最小的方案。AI (CI翻译)
- For each vertex
$i$($1 \leq i < 2^{N - 1}$), the integer written on vertex$i$is the absolute difference between the sum of the integers written on the vertices of the subtree rooted at vertex$2i$and the sum of the integers written on the vertices of the subtree rooted at vertex$2i+1$.
- 对于每个顶点
$i$($1 \leq i < 2^{N - 1}$),顶点$i$上写入的整数等于以顶点$2i$为根的子树中各顶点上写入的整数之和,与以顶点$2i+1$为根的子树中各顶点上写入的整数之和,这两个和的绝对差。
It can be proved that, under the constraints of this problem, a way of writing integers satisfying the condition always exists.
可以证明,在本题的约束条件下,满足条件的写法总是存在。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$2 \leq N \leq 18$- All input values are integers.
$2 \leq N \leq 18$- 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
N
NAI (CI翻译)
Output
输出格式
AI (CI翻译)Let $P_i$ be the integer written on vertex $i$ ($1 \leq i \leq 2^N - 1$), and output in the following format:
令 $P_i$ 表示顶点 $i$ 上写入的整数($1 \leq i \leq 2^N - 1$),请按以下格式输出:AI (CI翻译)
P_1 P_2 \cdots P_{2^N - 1}
P_1 P_2 \cdots P_{2^N - 1}AI (CI翻译)
$(P_1, P_2, \cdots, P_{2^N - 1})$ must be a permutation of $(1, 2, \cdots, 2^N - 1)$. If there are multiple ways of writing satisfying the condition that minimize the integer written on vertex $1$, any of them will be considered correct.
$(P_1, P_2, \cdots, P_{2^N - 1})$ 必须是 $(1, 2, \cdots, 2^N - 1)$ 的一个排列。如果有多种满足条件且能使顶点 $1$ 上写入的整数最小的写法,输出其中任意一种均可。AI (CI翻译)
样例
2
1 2 3
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。