静态建树判一下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;
}

最新文章

  1. DayPilot 7.9.3373 去掉DEMO
  2. 67. Container With Most Water
  3. Shell_参数替换(転)
  4. (转).net项目技术选型总结
  5. debian 学习记录-1 -安装
  6. iframe 适用高度
  7. 【转载】关于Python脚本开头两行的:#!/usr/bin/python和# -*- coding: utf-8 -*-的作用 – 指定文件编码类型
  8. 5.对象创建型模式-原型PROTOTYPE
  9. jquery获得表格可见行的大小数量
  10. React 实践项目 (五)
  11. Oracle-更新字段-一张表的字段更新另一张的表的字段
  12. 20165230 2017-2018-2 《Java程序设计》第2周学习总结
  13. nodejs+express+mysql 增删改查(二)
  14. 强化学习(五)用时序差分法(TD)求解
  15. oracle中date数据的转换问题
  16. PyCharm基本用法
  17. 使用 Maven 插件将 class(字节码文件),resource(资源文件),lib(依赖的jar包)分开打包
  18. [MapReduce_8] MapReduce 中的自定义分区实现
  19. Windows 下vim的配置文件_vimrc
  20. vuex使用一

热门文章

  1. c# ListBox
  2. VS2013修改resource之后产生designer1.cs
  3. vue-mixins使用注意事项和高级用法
  4. jmeter 多压力机并发测试过程
  5. codeforces 655A A. Amity Assessment(水题)
  6. python中的排序函数
  7. os.path
  8. 【leetcode刷题笔记】Remove Duplicates from Sorted Array II
  9. noip模拟赛 #3
  10. HDU3037Saving Beans(组合数+lucas定理)