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 }