2241 Sort binary Tree

Source: Internet
Author: User

2241 sort binary Tree

2001 CTSC National Trials

time limit: 1 sspace limit: 64000 KBtopic rank: Master Master SolvingTitle Description Description

A positive triangle with a side length of n can be divided into several small side length of 1 positive triangles, called unit triangles. The positive triangles of side length 3 are divided into three layers of 9 small positive triangles, and we numbered them from top to bottom, from left to right with 1~9. Similarly, a positive triangle with a side length of n can be divided into N2 units of triangles.

Four such side length of n can form a triangular pyramid. We will yield the three sides of the triangular pyramid in the clockwise order (from the top-bottom view) numbered A, B, C, and the bottom number is D. The sides of A, B, c triangle with the vertex of the pyramid as the top, the bottom of the D-triangle with it and A, B triangle of the intersection of the top. The diagram on the left is a three-pyramid-expanded plan, with dots on each face that are the top of the polygon, and the side a,b,c folded into the paper to revert to a triangular pyramid. We divide the A, B, C, D four polygons into N2 units of triangles.

For any two unit triangles, if there is an edge adjacent to each other, they are called adjacent unit triangles, and it is clear that each unit triangle has three adjacent unit triangles. Now, the 1~4n2 are randomly populated with four polygons in a total of 4n2 unit triangles.

You are now asked to program the largest ordered binary tree consisting of a unit triangle . The so-called maximum sort binary tree, refers to all of the units of the triangle composed of a sort of binary tree node most of the tree. For any unit triangle, choose one of the three adjacent unit triangles as the parent node, and the remaining two as the left child and right child respectively. Of course, the Unity Triangle does not need the parent node, while the left child and right child are not required for any node in the binary tree.

Enter a description Input Description

The first line is an integer n, followed by a 4n2 line, followed by a number filled with four polygons on a three pyramid.

Output description Output Description

It contains only an integer that represents the maximum number of nodes that the binary tree contains.

Sample input Sample Input

3

19

33

32

31

29

3

5

4

30

22

25

20

21st

12

24

23

34

35

14

13

15

26

18

17

8

16

27

11

10

9

1

28

7

2

6

36

Sample output Sample Output

17

Data range and Tips Data Size & Hint

1<=n<=18

Category labels Tags Click here to expandMemory Search Recursive Search the mainland region CTSC national team 2001 original title replay: Http://acm.wust.edu.cn/problem.php?id=2549&soj=8Description Input

The first line is an integer n (1<=n<=18), followed by a 4n2 line, followed by a number filled with four polygons on a three pyramid.

Output contains only an integer that represents the maximum number of nodes that the binary tree contains.

Sample Input
3193332312935430222520211224233435141315261817816271110912872636

Sample Output
17

No AC code

2241 Sort binary Tree

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.