PAT 1110. Complete Binary Tree

NO IMAGE
1 Star2 Stars3 Stars4 Stars5 Stars 給文章打分!
Loading...

1110. Complete Binary Tree (25)

Given a tree, you are supposed to tell if it is a complete binary
tree.

Input Specification:

Each input file contains one test case. For each case, the first line
gives a positive integer N (<=20) which is the total number of nodes
in the tree — and hence the nodes are numbered from 0 to N-1. Then N
lines follow, each corresponds to a node, and gives the indices of the
left and right children of the node. If the child does not exist, a
“-” will be put at the position. Any pair of children are separated by
a space.

Output Specification:

For each case, print in one line “YES” and the index of the last node
if the tree is a complete binary tree, or “NO” and the index of the
root if not. There must be exactly one space separating the word and
the number.

原題

判斷一顆二叉樹是不是完全的,只需要判斷能否用大小為n的堆來表示這棵樹。(樹的大小為n)
int nl[21]={-1},nr[21]={-1}

相關文章

程式語言 最新文章