Complete Binary Search Tree

PAT-1064

  • 本次因为涉及到完全二叉排序树,所以可以使用数组的形式来存储二叉排序树
  • 对输入序列排序后,得到的是中序遍历二叉排序树的序列。对这颗二叉排序树进行中序遍历,将每个结点的值放入二叉树的存储数组中,最后遍历数组即可求出层次遍历的序列。
  • 此题需要注意层次遍历和数组存储二叉树的关系,利用这个关系可以快速解题。
/**
* @Author WaleGarrett
* @Date 2020/9/5 8:20
*/ import java.util.Arrays;
import java.util.Scanner; /**
* PAT-1043,1064,1066,1086,1089,1099,1098
* 7
* 8 6 5 7 10 8 11
*/
public class PAT_1064 {
static final int maxn=1003;
static int[] node;
static int[] tree;//存储二叉树
static int N;
static int position=0;
static void inOrder(int root){
if(root>N)
return;
inOrder(root<<1);
tree[root]=node[position++];
inOrder(root<<1|1);
}
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int n=scanner.nextInt();
N=n;
node=new int[n];
tree=new int[n+1];
int i=0;
while(n!=0){
node[i]=scanner.nextInt();
i++;
n--;
}
Arrays.sort(node);
inOrder(1);
for(i=1;i<N;i++){
System.out.print(tree[i]+" ");
}
System.out.println(tree[N]);
}
}

PAT-1064(Complete Binary Search Tree)JAVA实现的更多相关文章

  1. PAT 1064 Complete Binary Search Tree[二叉树][难]

    1064 Complete Binary Search Tree (30)(30 分) A Binary Search Tree (BST) is recursively defined as a b ...

  2. PAT 1064 Complete Binary Search Tree

    #include <iostream> #include <cstdio> #include <cstdlib> #include <vector> # ...

  3. PAT甲级:1064 Complete Binary Search Tree (30分)

    PAT甲级:1064 Complete Binary Search Tree (30分) 题干 A Binary Search Tree (BST) is recursively defined as ...

  4. PAT题库-1064. Complete Binary Search Tree (30)

    1064. Complete Binary Search Tree (30) 时间限制 100 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...

  5. pat 甲级 1064. Complete Binary Search Tree (30)

    1064. Complete Binary Search Tree (30) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...

  6. 1064. Complete Binary Search Tree (30)【二叉树】——PAT (Advanced Level) Practise

    题目信息 1064. Complete Binary Search Tree (30) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B A Binary Search Tr ...

  7. PAT 甲级 1064 Complete Binary Search Tree (30 分)(不会做,重点复习,模拟中序遍历)

    1064 Complete Binary Search Tree (30 分)   A Binary Search Tree (BST) is recursively defined as a bin ...

  8. pat 甲级 1064 ( Complete Binary Search Tree ) (数据结构)

    1064 Complete Binary Search Tree (30 分) A Binary Search Tree (BST) is recursively defined as a binar ...

  9. PAT 甲级 1064 Complete Binary Search Tree

    https://pintia.cn/problem-sets/994805342720868352/problems/994805407749357568 A Binary Search Tree ( ...

  10. PAT Advanced 1064 Complete Binary Search Tree (30) [⼆叉查找树BST]

    题目 A Binary Search Tree (BST) is recursively defined as a binary tree which has the following proper ...

随机推荐

  1. Codeforces Round #665 (Div. 2) Distance and Axis、

    题目链接:Distance and Axis 题意:在ox轴上,给出点A的横坐标x,你可以向左或右移动点A(x+1/x-1),问你最小移动A的次数,以使得可以在ox轴上找到B点位置,B点满足从O到B的 ...

  2. Codeforces Round #540 (Div. 3) D2. Coffee and Coursework (Hard Version) (二分,贪心)

    题意:有\(n\)个数,每次可以选\(k(1\le k\le n)\)个数,并且得到\(a_1+max(0,a_2-1)+max(0,a_3-2)+...+max(0,a_k-k+1)\)的贡献,问最 ...

  3. BIM轻量化——浏览器展示

    此篇博客仅为记录,记录钻研过程的零碎思路.         之前考虑过很多可能性,对rvt文件转换格式:.obj.JSON..gltf等等.这些可能性前人一般都尝试过,而且也都做出来了东西.     ...

  4. MySQL 字符集及校验规则

    字符集 Mysql 的字符集有4个级别的默认设置:服务器级,数据库级,表级和字段级,客户端交互时,也可以指定字符集 # 字符集:是一个系统支持的所有抽象字符的集合.字符是各种文字和符号的总称,包括各国 ...

  5. SDN总结

    之前做项目用到了SDN,知道其作用,但是对其不是特别熟悉,今天特来总结一下相关知识点: 1. SDN的典型架构分为哪三层 主要分为应用层,控制层,和基础设施层: 2. SDN技术的关键点是 控制平面和 ...

  6. codeforces 8B

    B. Obsession with Robots time limit per test 2 seconds memory limit per test 64 megabytes input stan ...

  7. Caffe入门:对于抽象概念的图解分析

    Caffe的几个重要文件 用了这么久Caffe都没好好写过一篇新手入门的博客,最近应实验室小师妹要求,打算写一篇简单.快熟入门的科普文. 利用Caffe进行深度神经网络训练第一步需要搞懂几个重要文件: ...

  8. SPOJ - LCS2 Longest Common Substring II(后缀自动机)题解

    题意: 求\(n\)个串的最大\(LCS\). 思路: 把第一个串建后缀自动机,然后枚举所有串.对于每个串,求出这个串在\(i\)节点的最大匹配为\(temp[i]\)(当前串在这个节点最多取多少), ...

  9. CS144学习(2)TCP协议实现

    Lab1-4 分别是完成一个流重组器,TCP接收端,TCP发送端,TCP连接四个部分,将四个部分组合在一起就是一个完整的TCP端了.之后经过包装就可以进行TCP的接收和发送了. 代码全部在github ...

  10. chmod +x vs chmod 755

    chmod +x vs chmod 755 What is the difference between "chmod +x" and "chmod 755"? ...