2977 二叉堆练习1 codevs

题目描述  Description

已知一个二叉树,判断它是否为二叉堆(小根堆)

输入描述  Input Description

二叉树的节点数N和N个节点(按层输入)

输出描述  Output Description

YES或NO

样例输入  Sample Input

样例输入1

3

1 4 9

样例输入2

3

6 4 9

样例输出  Sample Output

样例输出1

YES

样例输出2

NO

数据范围及提示  Data Size & Hint

对于20%的数据  N≤20

对于50%的数据  N≤1000

对于100%的数据 N≤50000,每个节点≤10000

#include <cstdio>
#include <iostream>
using namespace std;
int n,tree[60000];
bool pq;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    scanf("%d",&tree[i]);
    for(int i=1;i<=n;i++)
    for(int j=i;j<=n;j=j*2)
    if(tree[i]>tree[j])
    {
        pq=1;
        break;
    }
    if(pq==true)
    printf("NO");
    else
    printf("YES");
    return 0;
}

 

转载于:https://www.cnblogs.com/sssy/p/6664992.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值