Topic 1176: Tree Lookup

Source: Internet
Author: User

Topic 1176: Tree Lookup

time limit:1 seconds

Memory limit:32 MB

Title Description:

There is a tree that outputs all the nodes of a certain depth, and then outputs the nodes, none outputs empty. The tree is a completely binary tree.

Input:

Enter more than one set of data.
Enter one n (1<=n<=1000) per group, then enter the n nodes in the tree sequentially, and then enter a D to represent the depth.

Output:

Output all nodes of layer d in the tree, separated by spaces between nodes, and no spaces after the last node.

Sample input:
41 2 3 42
Sample output:
2 3
#include <iostream>#include<string.h>#include<stdio.h>#include<math.h>using namespacestd;inta[1002];intMain () {intN;  while(SCANF ("%d", &n)! =EOF) {        intDepth=0; inttmp=N; intBegin,end;  while(TMP)//determine how many layers there are{tmp/=2; Depth++; }         for(intI=0; i<n;i++) {scanf ("%d",&A[i]); }        intD//number of layers to findscanf"%d",&d); if(d<=0|| D>depth) {printf ("empty\n");  Break; }Else{begin=(int) Pow (2.0, d1)-1; End=(int) Pow (2.0, d)-2; if(d==depth) {End=n-1; }} printf ("%d", A[begin]);  for(inti=begin+1; i<=end;i++) {printf ("%d", A[i]); } printf ("\ n"); }    return 0;}

Topic 1176: Tree Lookup

Related Article

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.