首页
DreamJudge
院校信息
考研初试
机试真题
讨论区
兑换中心
登录
注册
上岸
以下题解仅供学习参考使用。
抄袭、复制题解,以达到刷AC率/AC数量或其他目的的行为,在N诺是严格禁止的。
N诺非常重视学术诚信。此类行为将会导致您成为作弊者。具体细则请查看N诺社区规则。
cczz
2025年8月13日 17:24
二叉树 题解:
P1233
回复 0
|
赞 0
|
浏览 167
利用完全二叉树的性质:父节点 = 子节点 / 2 #include<bits/stdc++.h> using namespace std; int main(){ int x, y; while(cin >> x >> y){ while(x != y){ if(x < y) y /= 2; else x /= 2; } cout << x << endl; } }
emoji
2025年3月20日 21:13
二叉树 题解:
P1233
回复 0
|
赞 3
|
浏览 528
观察可知,i节点的父节点是i/2,由此可知可以通过除以2的方法求父节点 #include<iostream> using namespace std; int main(){ int a,b; while(cin>>a>>b){ while(a!=b){ a>b?a=a/2:b=b/2; } cout<<a<<endl; } return 0; }
dhh390
2025年3月14日 16:52
二叉树 题解:
P1233
回复 0
|
赞 2
|
浏览 613
#include <stdio.h> #include <string.h> #include<stdlib.h> #include<math.h> int main() { int x,y; while(scanf("%d %d",&x,&y)!=EOF) { int a[1000]={0}; &...
carrot_huan
2025年3月6日 17:46
二叉树 题解:说实话,没看懂题目那个递推式子,但是确实做出来了
P1233
回复 0
|
赞 4
|
浏览 788
#include<iostream> using namespace std; long long int cal(long long int n1,long long int n2) { if (n1 == n2) return n1; if (n1 > n2) return cal(n1 / 2, n2); return cal(n1, n2 / 2); } int main()&nbs...
西电机试专家
2025年2月28日 11:47
二叉树 题解:好看
P1233
回复 0
|
赞 6
|
浏览 761
#include<bits/stdc++.h> using namespace std; //思路,哪个数大,给哪个数除以2 int main () { int a,b; while(cin>>a>>b) { while(a>=1&&b>=1){ &...
Cookie‘s AE86
2024年3月25日 18:55
二叉树 题解:
P1233
回复 0
|
赞 2
|
浏览 1.4k
#include<bits/stdc++.h> using namespace std; int main(){ int x,y; while(cin >> x >> y){ while(x != y){ if(x > y) x /= 2; else y /= 2; } cout << x << endl; }...
小李122333
2024年1月17日 17:27
二叉树 题解:c++
P1233
回复 1
|
赞 13
|
浏览 1.7k
#include <bits/stdc++.h> using namespace std; int main(){ int x,y; while(cin>>x>>y){ while(x!=y){ if(x>y) x/=2; else y/=2; } cout<<x<<endl; } }
1935569240
2024年3月8日 14:18
二叉树 题解:代码如下,递归
P1233
回复 0
|
赞 1
|
浏览 1.1k
#include<iostream> #include<algorithm> #include<string> using namespace std; int a[100],b[100], cnt = 0,aNum,bNum; void searchRoute(int x,int flag) { if (x == 1) { if (flag == 0) { ...
shmilyzsc
2021年2月21日 12:32
利用完全二叉树的性质
P1233
回复 0
|
赞 3
|
浏览 9.1k
#include <bits/stdc++.h> using namespace std; int main() { int a,b,x; //其父亲节点编号为[n/2] while(cin >> a >> b) { while(a != b) { if(a > b) a /= 2; else b /= 2; } cout << a << endl; } return 0; }
James
2021年2月1日 13:17
完全二叉树的LCA简洁代码
P1233
回复 0
|
赞 2
|
浏览 10.7k
#include<iostream> using namespace std; int main(){ int x,y; while(scanf("%d %d",&x,&y)!=EOF){ while(x!=y){ if(x>y){ ...
1
2
题目
二叉树
题解数量
15
发布题解
在线答疑
热门题解
1
二叉树 题解:c++
2
二叉树 题解:好看
3
二叉树 题解:说实话,没看懂题目那个递推式子,但是确实做出来了
4
利用完全二叉树的性质
5
二叉树 题解:
6
完全二叉树的LCA简洁代码
7
二叉树 题解:
8
二叉树 题解:
9
完全/满二叉树可以用虚拟数组模拟
10
二叉树 题解:代码如下,递归