FrabonacciTree
TCCC07 Sponsor 4 · 2007-07-30 · by Mike Mirzayanov
Problem Statement
The 0-th and 1-st Frabonacci trees are each single nodes. For all i > 1, the i-th Frabonacci tree is constructed as follows:
- Create a new node r. This will be the root node of the i-th Frabonacci tree.
- Construct the (i-1)-th and (i-2)-th Frabonacci trees.
- Attach the (i-2)-th Frabonacci tree as the left subtree of r.
- Attach the (i-1)-th Frabonacci tree as the right subtree of r.
To traverse a Frabonacci tree in preorder, perform the following operations:
- Visit the root.
- Traverse the left subtree.
- Traverse the right subtree.
You are given three
Constraints
- n will be between 0 and 50, inclusive.
- startIndex will be between 1 and 1000000000, inclusive.
- finishIndex will be between 1 and 1000000000, inclusive.
- startIndex, finishIndex less or equal than the number of vertices in the n-th Frabonacci tree.
3 2 4 Returns: "URL"
3 4 2 Returns: "UUL"
3 5 4 Returns: "UL"
12 10 10 Returns: ""
3 1 2 Returns: "L"
Submissions are judged against all 192 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class FrabonacciTree with a public method string shortestPath(int n, int startIndex, int finishIndex) · 192 test cases · 2 s / 256 MB per case