静态建树判一下1-n是不是为空就好了,如果有空的  就说明不是complete binary tree

(和线段树建树差不多啊)Left=2*root;Right=2*root+1

#include <bits/stdc++.h>
using namespace std;
typedef long long LL; struct BT{
int Left;
int Right;
int w;
}q[2000100];
bool vis[2000100]; void Build(int root,int x)
{
if(!vis[root])
{
vis[root]=true;
q[root].w=x;
q[root].Left=2*root;
q[root].Right=2*root+1;
return;
}
if(q[root].w>x)
Build(2*root+1,x);
else
Build(2*root,x);
} int main()
{
int n,x;
memset(vis,false,sizeof(vis));
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&x);
Build(1,x);
}
bool flag=false;
queue<int>que;
que.push(1);
while(!que.empty())
{
int x=que.front();que.pop();
if(flag) printf(" ");
printf("%d",q[x].w);
flag=true;
int Left=2*x;
if(vis[Left]) que.push(Left);
int Right=2*x+1;
if(vis[Right]) que.push(Right); } puts("");
for(int i=1;i<=n;i++)
if(!vis[i]){
puts("NO");
return 0;
}
puts("YES");
return 0;
}

PAT L3-010【完全二叉树】的更多相关文章

  1. PAT天梯赛练习题 L3-010. 是否完全二叉搜索树(完全二叉树的判断)

    L3-010. 是否完全二叉搜索树 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 将一系列给定数字顺序插入一个初始为空的二叉搜 ...

  2. PAT A1110 Complete Binary Tree (25 分)——完全二叉树,字符串转数字

    Given a tree, you are supposed to tell if it is a complete binary tree. Input Specification: Each in ...

  3. PAT A1123 Is It a Complete AVL Tree (30 分)——AVL平衡二叉树,完全二叉树

    An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child sub ...

  4. PAT A1155 Heap Paths (30 分)——完全二叉树,层序遍历,特定dfs遍历

    In computer science, a heap is a specialized tree-based data structure that satisfies the heap prope ...

  5. PAT甲题题解-1110. Complete Binary Tree (25)-(判断是否为完全二叉树)

    题意:判断一个节点为n的二叉树是否为完全二叉树.Yes输出完全二叉树的最后一个节点,No输出根节点. 建树,然后分别将该树与节点树为n的二叉树相比较,统计对应的节点个数,如果为n,则为完全二叉树,否则 ...

  6. PAT 1110 Complete Binary Tree[判断完全二叉树]

    1110 Complete Binary Tree(25 分) Given a tree, you are supposed to tell if it is a complete binary tr ...

  7. PAT甲级——1110 Complete Binary Tree (完全二叉树)

    此文章同步发布在CSDN上:https://blog.csdn.net/weixin_44385565/article/details/90317830   1110 Complete Binary ...

  8. PAT A1147 Heaps (30 分)——完全二叉树,层序遍历,后序遍历

    In computer science, a heap is a specialized tree-based data structure that satisfies the heap prope ...

  9. pat甲级题解(更新到1013)

    1001. A+B Format (20) 注意负数,没别的了. 用scanf来补 前导0 和 前导的空格 很方便. #include <iostream> #include <cs ...

随机推荐

  1. node.js+express+jade系列四:jade嵌套的使用

    jade是express自带的模板引擎 jade文件可以嵌套使用,include引用外部jade文件,extends引用jade模板 例如 有一个主jade文件layout.jade,引用top.ja ...

  2. Java企业微信开发_05_消息推送之被动回复消息

    一.本节要点 1.消息的加解密 微信加解密包 下载地址:http://qydev.weixin.qq.com/java.zip      ,此包中封装好了AES加解密方法,直接调用方法即可. 其中,解 ...

  3. Java微信开发_03_使用测试号进行开发

    今天进行自定义菜单的开发时,发现公众号没有自定义菜单的权限.于是想到用测试号,但微信服务器如何区分你要请求的是公众号还是测试号呢. 我们可以发现不同公众号的appID和appsecre是不同的,一对a ...

  4. MessFormat的简单使用

    MessageFormat用法java.text.MessageFormat 作用:MessageFormat 获取一组对象,格式化这些对象,然后将格式化后的字符串插入到模式中的适当位置. Messa ...

  5. 基于v4l2 ffmpeg x264的视频远程监控(附上编译好的库文件)

    说明:主要是基于ghostyu网友整理的< arm mini2440 基于v4l2 ffmpeg x264的视频远程监控>.自己做了一遍,遇到不少问题,就整理记录下来. 1.平台 硬件:a ...

  6. HDU5768Lucky7(中国剩余定理+容斥定理)(区间个数统计)

    When ?? was born, seven crows flew in and stopped beside him. In its childhood, ?? had been unfortun ...

  7. Java如何调用dll

    -----------------------------前置条件------------------------------------- 1. 首先有testdll.dll 2. 需要testdl ...

  8. BZOJ2548:[CTSC2002]灭鼠行动

    我对模拟的理解:https://www.cnblogs.com/AKMer/p/9064018.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem ...

  9. bzoj 3083 遥远的国度 —— 树链剖分

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3083 换根后路径还是不变,子树分类讨论一下,树剖后线段树维护即可. 代码如下: #inclu ...

  10. 记一次肉机事件--yam

    背景: 研发同事反应他自己的测试机器,有一个yum程序占用cpu很多,接近100%,然后他就将这个程序kill了.我一看他给我发的截图,原来不是“yum”,而是“yam”,第一反应就是让人当肉机了.上 ...