首页
DreamJudge
院校信息
考研初试
考研复试
保研专区
讨论区
兑换中心
登录
注册
上岸
以下题解仅供学习参考使用。
抄袭、复制题解,以达到刷AC率/AC数量或其他目的的行为,在N诺是严格禁止的。
N诺非常重视学术诚信。此类行为将会导致您成为作弊者。具体细则请查看N诺社区规则。
Tyu0871
2026年3月19日 23:38
树查找 题解:数组存放完全二叉树 C语言
P1386
回复 0
|
赞 4
|
浏览 113
根据我们初试学过的数据结构,完全二叉树的下标是下面这样的: 1 2 3 4 5 6 7 8..... 那么就有第d层(d=n-1)的节点下标范围为[2^(n-1),2^(n)-1]。 那么完全二叉树的遍历也变得简单起来了: #include <stdio.h> #include <math.h> #include <stdbool.h> int a[1001]; int main(){ int n; while(scanf("%d", &n...
ZeroQi_404
2026年3月17日 22:09
树查找 题解:
P1386
回复 0
|
赞 3
|
浏览 58
#include <iostream> #include <cmath> using namespace std; int main(){ int n; while(cin >> n){ int a[1005]; for(int i = 1; i <= n; i++){ cin >> a[i]; } int m; cin >> m; int ...
dyf123
2026年3月10日 19:03
树查找 题解:
P1386
回复 0
|
赞 1
|
浏览 128
#include <iostream> #include <bits/stdc++.h> using namespace std; int main(){ int n; while(cin>>n){ //顺序存储的树 int num[1000]; ...
RingoCrystal
2025年2月11日 16:49
树查找 题解:数学解
P1386
回复 0
|
赞 6
|
浏览 1.2k
#include <bits/stdc++.h> using namespace std; int getPos(int h){ return (1 << (h-1)) - 1; // 2^(h-1) - 1 } int main() { int n; while(cin>>n){ vector<int> a(n),b; for(int i=0;i<n;i++)cin>>a[i]; int h;cin>>...
小王桐学
2024年2月28日 23:09
树查找 题解:C
P1386
回复 0
|
赞 4
|
浏览 1.3k
#include <stdio.h> #include <math.h> int main() { int k,i,n,a[1000],d; while(scanf("%d",&n) != EOF) { for(i = 1; i <= n; i++) scanf("%d",&a[i]); scanf("%d",&d); k = pow(2,d-1); //k为第d层第一个节点的下标 if(n < k) printf("EMPTY\n"); else if(n >...
帅就一个字
2023年4月10日 01:18
两种方法进行树查找
P1386
回复 0
|
赞 4
|
浏览 2.8k
方法一:利用完全二叉树的性质,除最后一层外都是满二叉树,且最后一层的叶子结点都集中在树的左侧 #include <bits/stdc++.h> using namespace std; int n, d;//n代表节点个数,d代表深度 void input(vector<int> &arr){ for(int i = 0; i < n; i++){ cin >> arr[i]; } } int main(){ while(cin >> n){ ...
kas
2022年3月17日 09:33
树查找
P1386
回复 0
|
赞 7
|
浏览 5.0k
#include<iostream> #include<cmath> using namespace std; int main() { int n, num[1001], i, deep; cin >> n; for (i = 1; i <= n; ++i) cin >> num[i]; &...
题目
树查找
题解数量
7
发布题解
在线答疑
热门题解
1
树查找
2
树查找 题解:数学解
3
树查找 题解:C
4
树查找 题解:数组存放完全二叉树 C语言
5
两种方法进行树查找
6
树查找 题解:
7
树查找 题解: