当前位置:网站首页>Binary tree (day 82)
Binary tree (day 82)
2022-07-27 03:40:00 【Zhangxueheng】
List of articles
1: subject
1
/ \
2 3
/ \ / \
4 5 6 7
/\ /\ /\ /\
... ...
As shown in the figure above , From positive integers 1,2,3,… Formed an infinite ( full ) Binary tree .
From any node to the root node ( The number is 1 The node of ) There is a unique path , For instance from 5 The path to the root node is (5,2,1), from 4 The path to the root node is (4,2,1), From the root 1 The path to the root node contains only one node 1, So the path is (1).
For two nodes x and y, Suppose their paths to the root node are (x1,x2,…,1) and (y1,y2,…,1), Then there must be two positive integers i and j, Make from xi and yj Start , Yes xi=yj,xi+1=yj+1,xi+2=yj+2,…
The problem now is , Given x and y, Ask their public parent , namely xi( That is to say yj).
Input format
1≤x,y≤231−1
sample input :
10 4
sample output :
2
2: Code implementation
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int x, y;
cin >> x >> y;
while (x != y)
{
if (x > y) x /= 2;
else y /= 2;
}
cout << x << endl;
return 0;
}
边栏推荐
- mysql如何优化
- Basic concept and essence of Architecture
- Annotation summary of differences between @autowired and @resource
- 阿里 Seata 新版本终于解决了 TCC 模式的幂等、悬挂和空回滚问题
- The diagram of user login verification process is well written!
- 【1206. 设计跳表】
- Pytorch损失函数总结
- Add support for @data add-on in idea
- Redis source code learning (33), command execution process
- 索引最佳实践
猜你喜欢

app端接口用例设计方法和测试方法

Pytorch损失函数总结

Idea 中添加支持@Data 插件

数字孪生实际应用:智慧城市项目建设解决方案

Kettle读取按行分割的文件

spark:地区广告点击量排行统计(小案例)

Introduction to database - a brief introduction to MySQL

Code review pyramid

JMeter distributed pressure measurement

Practice of online problem feedback module (XV): realize the function of online updating feedback status
随机推荐
OC message mechanism
Technology vane | interpretation of cloud native technology architecture maturity model
mysql出现不存在错误
Insert pictures and videos in typera
技术风向标 | 云原生技术架构成熟度模型解读
Wechat applet generation Excel
The function and application of lpci-252 universal PCI interface can card
Spark: ranking statistics of regional advertising hits (small case)
768. Block II greed that can complete sorting at most
opiodr aborting process unknown ospid (21745) as a result of ORA-609
app端接口用例设计方法和测试方法
渗透测试-后渗透-痕迹清理
How to conduct 360 assessment
【树链剖分】模板题
MySQL underlying data structure
spark学习笔记(六)——sparkcore核心编程-RDD行动算子
《稻盛和夫给年轻人的忠告》阅读笔记
Details of impala implementation plan
What are "full five unique" and "full two unique"? Any difference?
Practice of online problem feedback module (XV): realize the function of online updating feedback status