2879 heap judgment and 2879 judgment

Source: Internet
Author: User

2879 heap judgment and 2879 judgment
2879 heap judgment

 

Time Limit: 1 s space limit: 32000 KB title level: Gold Title Description Description

Heap is a common data structure. The binary heap is a special binary tree. His father's day is bigger than the two son nodes, and his left and right subtree is also a binary heap. Enter a tree (represented by an array of Binary Trees, that is, the left and right sons of a [I] are a [2i], a [2i + 1]). determine whether it is a heap.

Input description Input Description

An integer N indicates the number of knots.

N integers in the second row, indicating the numbers represented by each node

Output description Output Description

If Yes, 'yes' is output'

Otherwise, 'no' is output'

Sample Input Sample Input

5

1 2 3 4 5

Sample output Sample Output

No

Data range and prompt Data Size & Hint

1 <N <100

The number is less than 2 ^ 31.

 1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 int a[1001]; 5 int main() 6 { 7     int n; 8     scanf("%d",&n); 9     for(int i=1;i<=n;i++)10     {11         //int d;12         scanf("%d",&a[i]);13     }14     int flag=0;15     for(int i=1;i<=n;i++)16     {17         if(a[2*i]>a[i]||a[2*i+1]>a[i])18         {19             flag=1;20             break;21         }22         else23         {24             continue;25         }26     }27     if(flag==1)28     {29         cout<<"No";30     }31     else32     {33         cout<<"Yes";34     }35     return 0;36 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.