当前位置:网站首页>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;
}
边栏推荐
- Typescript TS basic knowledge interface, generics
- 智能体重秤方案主控采用CSU18M91
- Learn the recycling mechanism of recyclerview again
- Byte side: can TCP and UDP use the same port?
- [1206. Design skip table]
- The diagram of user login verification process is well written!
- 在typora中插入图片和视频
- OC message mechanism
- Customer cases | pay attention to the elderly user experience, and the transformation of bank app to adapt to aging should avoid falsehood and be practical
- The new version of Alibaba Seata finally solves the idempotence, suspension and empty rollback problems of TCC mode
猜你喜欢

Quick sequencing and optimization

深入理解Mysql索引底层数据结构与算法

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

阿里 Seata 新版本终于解决了 TCC 模式的幂等、悬挂和空回滚问题

477-82(236、61、47、74、240、93)

JMeter distributed pressure measurement

MySQL underlying data structure

Win10/win11 lossless expansion of C disk space, cross disk consolidation of C and e disks

Byte side: can TCP and UDP use the same port?

基于OpenCV的轮廓检测(2)
随机推荐
榕树贷款,
Kettle读取按行分割的文件
技术风向标 | 云原生技术架构成熟度模型解读
Practical application of digital twins: smart city project construction solution
MySQL Chinese failure
Record the problem of PHP program accessing system files incorrectly
【无标题】JDBC连接数据库读超时
Member array and pointer in banyan loan C language structure
[1206. Design skip table]
Banyan loan,
Common weak password Encyclopedia
$128million! IQM, a Finnish quantum computing company, was supported by the world fund
[common search questions] 111
Double disk: the main differences between DFS and BFS, the differences in ideology, and the differences in code implementation
将幕布文章OPML转换为Markdown的方法
Mysql: summary of common sub database and sub table schemes of Internet companies
Graphic SQL, this is too vivid!
477-82(236、61、47、74、240、93)
768. 最多能完成排序的块 II 贪心
spark学习笔记(五)——sparkcore核心编程-RDD转换算子