社区讨论
20pts神秘错误
P2171Hz 吐泡泡参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mhjhpk2l
- 此快照首次捕获于
- 2025/11/04 02:45 4 个月前
- 此快照最后确认于
- 2025/11/04 02:45 4 个月前
20pts,对了测试点3和10,有么有dalao帮帮忙(求求了),蒟蒻会留下ta的关注!(我的编程老师也没改出来)
CPP#include <bits/stdc++.h>
using namespace std;
struct node{
node* lchild;
node* rchild;
int num;
};
int k,ans;
node* head;
void deep(int d,node* h){
if(h->lchild!=NULL)deep(d+1,h->lchild);
if(h->rchild!=NULL)deep(d+1,h->rchild);
ans=max(ans,d);
return;
}
void push(int x,node* h){
if(h->lchild!=NULL&&x<h->num){
push(x,h->lchild);
return;
}
if(h->rchild!=NULL){
push(x,h->rchild);
return;
}
node* t=new node;
t->lchild=t->rchild=NULL;
t->num=x;
if(x<h->num)h->lchild=t;
else h->rchild=t;
}
void out(node* h){
if(h==NULL)return;
out(h->lchild);
out(h->rchild);
cout << h->num << '\n';
}
int main(){
int n;
cin >> n;
cin >> k;
head=new node;
head->num=k;
head->lchild=head->rchild=NULL;
for(int i=1;i<n;i++){
cin >> k;
push(k,head);
}
deep(1,head);
cout << "deep=" << ans << '\n';
out(head);
return 0;
}
这份代码在样例中输出了"deep=6",接下来的后序遍历没有问题,但手动将深度减一得0pts,不知道问题在哪里(v_v)。
回复
共 0 条回复,欢迎继续交流。
正在加载回复...