编程介的小学生 2019-06-10 21:09 采纳率: 20.5%
浏览 206

根据规则扩展二叉树的实现原理,使用C语言的程序编写设计思想的方式怎么完成

Problem Description
There are many questions about the tree, most of them are Binary tree. But now, I’m tired of it. In this problem, we will not talk about the binary tree again, we discuss the tree which has three sub-trees, we called it extend tree;

The extend tree is orderly, it means that every integer n(n>=0) correspond to one unique extend tree and each extend tree correspond to one unique number. The tree is numbered using the following scheme:

  1. The empty tree is numbered 0;
  2. The single-node tree is numbered 1;
  3. All extend trees that has m nodes correspond to a smaller integer than the tree which has more than m nodes.
  4. Any extend tree having m nodes with left, mid and right sub-trees L ,M and R is numbered n; such that all trees having m nodes numbered > n have either Left sub-trees numbered higher than L, or A left sub-tree = L and a mid sub-tree numbered higher than M, or a left sub-tree = L a mid sub-tree = M and a right sub-tree numbered higher than R.

The first 18 extend trees are show below:

Your job for this problem is to output a extend tree when its order number is given.

Input
The first line contains a single positive integer T( T <= 3000 ), indicating the number of datasets.
Each instance consist of a single integer n, where 1<= n <=10^14.

Output
For each problem instance, you should output one line containing the tree corresponding to the order number for that instance. To print out the tree, use the following scheme:
A tree with no children should be output as X. A tree with left, mid and right sub-trees L M, and R should be output as (L)(M)(R)X, where L M, and R are the representations of L M, and R.
If L is empty, just output (M)(R)X.
If M is empty, just output (L)(R)X.
If R is empty, just output (L)(M)X.
If L and M is empty, just output (R)X.
...
The answer of other conditions has the same format.

Sample Input
10
1
2
3
4
5
6
7
8
9
10

Sample Output
Case #1: X
Case #2: (X)X
Case #3: (X)X
Case #4: (X)X
Case #5: ((X)X)X
Case #6: ((X)X)X
Case #7: ((X)X)X
Case #8: (X)(X)X
Case #9: ((X)X)X
Case #10: ((X)X)X

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
    • ¥20 matlab yalmip kkt 双层优化问题
    • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
    • ¥88 实在没有想法,需要个思路
    • ¥15 MATLAB报错输入参数太多
    • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
    • ¥15 有赏,i卡绘世画不出
    • ¥15 如何用stata画出文献中常见的安慰剂检验图
    • ¥15 c语言链表结构体数据插入