2021FDU机试1
作者:
等待风起飞
,
2024-03-20 14:36:25
,
所有人可见
,
阅读 5
#include<iostream>
#include<stdlib.h>
using namespace std;
const int N=100;
const int INF=0x3f3f3f3f;
int tree[N];
void preorder(int idx,int maxi,int& ans,int n){
if(idx>=n)return;
if(tree[idx]>=maxi)ans++;
preorder(2*idx+1,max(maxi,tree[idx]),ans,n);
preorder(2*idx+2,max(maxi,tree[idx]),ans,n);
}
int main(){
int idx=0,n=0;
string cur;
while(cin>>cur){
if(cur=="null")tree[idx++]=-1;
else tree[idx++]=atoi(cur.c_str());
n++;
}
int ans=0;
preorder(0,-INF,ans,n);
cout<<ans;
return 0;
}