2017-3-15
这个题目让我们找到两个节点的最大公共节点,我们不难发现二叉树的性质,父节点的值是子节点值的1/2,利用这个特点我们可以一步步的向上找。
#include<iostream>
using namespace std;
int x,y;
int dfs(
int i,
int j){
if (i==j)
return i;
if (i>j){
return dfs(i/
2,j);
}
else{
return dfs(i,j/
2);
}
}
int main(){
while (
cin>>x>>y){
cout<<dfs(x,y)<<endl;
}
return 0;
}
转载请注明原文地址: https://www.6miu.com/read-2626835.html