题意:

输入一个正整数N(<=1000),接着输入N个整数([-1000,1000]),依次插入一棵初始为空的二叉排序树。输出最底层和最底层上一层的结点个数之和,例如x+y=x+y。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
typedef struct Node{
int value;
int vis;
int level;
int visl,visr;
Node *lchild,*rchild;
}node;
int a[];
int num[];
void insert_(node *now,int x,int y){
if(now->vis==){
now->value=x;
now->vis=;
now->level=y;
++num[y];
return ;
}
if(x<=now->value){
if(now->visl==){
now->lchild=new node();
now->visl=;
}
insert_(now->lchild,x,+y);
}
else{
if(now->visr==){
now->rchild=new node();
now->visr=;
}
insert_(now->rchild,x,+y);
}
return ;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for(int i=;i<=n;++i)
cin>>a[i];
node *root=new node();
root->value=a[];
root->vis=;
root->level=;
++num[];
for(int i=;i<=n;++i)
insert_(root,a[i],);
int mx=;
for(int i=;i<n;++i)
if(num[i])
mx=i;
cout<<num[mx]<<" + "<<num[mx-]<<" = "<<num[mx]+num[mx-];
return ;
}

【PAT甲级】1115 Counting Nodes in a BST (30分)(二叉查找树)的更多相关文章

  1. PAT 甲级 1115 Counting Nodes in a BST

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

  2. PAT Advanced 1115 Counting Nodes in a BST (30) [⼆叉树的遍历,BFS,DFS]

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

  3. PAT A 1115. Counting Nodes in a BST (30)【二叉排序树】

    题目:二叉排序树,统计最后两层节点个数 思路:数组格式存储,insert建树,dfs遍历 #include<cstdio> #include<iostream> #includ ...

  4. [二叉查找树] 1115. Counting Nodes in a BST (30)

    1115. Counting Nodes in a BST (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...

  5. PAT甲1115 Counting Nodes in a BST【dfs】

    1115 Counting Nodes in a BST (30 分) A Binary Search Tree (BST) is recursively defined as a binary tr ...

  6. PAT甲级——A1115 Counting Nodes in a BST【30】

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

  7. PAT甲题题解-1115. Counting Nodes in a BST (30)-(构建二分搜索树+dfs)

    题意:给出一个序列,构建二叉搜索树(BST),输出二叉搜索树最后两层的节点个数n1和n2,以及他们的和sum: n1 + n2 = sum 递归建树,然后再dfs求出最大层数,接着再dfs计算出最后两 ...

  8. PAT (Advanced Level) 1115. Counting Nodes in a BST (30)

    简单题.统计一下即可. #include<cstdio> #include<cstring> #include<cmath> #include<vector& ...

  9. 1115. Counting Nodes in a BST (30)

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

随机推荐

  1. 从HTML到node.js以及跨域问题的解决

    废话不多说,直接上代码 网页客户端 <!DOCTYPE html> <html> <head> <meta http-equiv="Content- ...

  2. C# 截取屏幕

    /// <summary> /// 截取屏幕 /// </summary> /// <param name="x">起点X坐标</para ...

  3. day7 基础数据类型&集合&深浅拷贝

    基础数据类型汇总: #!/usr/bin/env python # -*- coding:utf-8 -*- ''' str int ''' # str s = ' a' print(s.isspac ...

  4. 浅谈python的第三方库——numpy(一)

    python作为广受欢迎的一门编程语言,其中很重要的一个原因便是它可以使用很多第三方库. 对第三方库的理解,在笔者看来就是一些python爱好者和专门的研发机构,为满足某一特定应用领域的需要,使用py ...

  5. 斯坦福发布2019全球AI报告:中国论文数量超美国,自动驾驶汽车领域获投资最多

    近日,斯坦福联合MIT.哈佛.OpenAI等院校和机构发布了一份291页的<2019年度AI指数报告>. 这份长达291页的报告从AI的研究&发展.会议.技术性能.经济.教育.自动 ...

  6. 数据库MySQL中关于“多表关联更新”的那些事

    在常见的sql中,我们经常在查询中进行多表关联查询,用的比较熟练.今天在开发中遇到一个实际业务场景是多表关联更新,一时不知所措.本着多学习的态度,没有直接写java代码去实现,终于把多表关联更新的sq ...

  7. Java设计模式(一)UML总结

    定义 统一建模语言(英语: Unified Modeling Language ,缩写UML)是非专利的第三代建模和规约语言. UML特点 UML是一种开放的方法 用于说明.可视化.构建和编写一个正在 ...

  8. webkit 技术内幕 笔记 二

    浏览器历史 80年代末-90年代初:worldwideweb(nexus) -- Berners-Lee 1993: Mosaic浏览器,后来叫网景(Netscape)--Marc Andreesse ...

  9. 如何在Mac OS X上将PDF转换为Microsoft Word

    Lighten PDF to Word Converter for Mac是一个简单但功能强大的应用程序,可将PDF文件准确,轻松地转换为Microsoft Word.它可以保留原始内容的布局,格式, ...

  10. beego控制器介绍

    控制器介绍 提示:在 v1.6 中,此文档所涉及的 API 有重大变更,this.ServeJson() 更改为 this.ServeJSON(),this.TplNames 更改为 this.Tpl ...