Full Binary Tree(sdut 2882)
Problem Description:
Output
Sample Input
5
1 2
2 3
4 3
1024 2048
3214567 9998877
题解 只要找到公共节点即可,水题一个;
#include<stdio.h>
#include<string.h>
int main()
{
long long int i,j,a,b,m,n,p;
scanf("%lld",&p);
for(int k=;k<p;k++)
{
scanf("%lld%lld",&a,&b);
m=a>b?a:b;
n=a>b?b:a;
long long int count1=,count2=;
while(m!=n)
{
if(n>m)
n/=;
if(m==n)
break;
if(m>n)
m/=;
}//找到公共节点;
while(a!=m)
{
a/=;
count1++;
}
while(b!=m)
{
b/=;
count1++;
}//统计下每一节点到公共节点的距离
printf("%lld\n",count1); }
return ;
}
Full Binary Tree(sdut 2882)的更多相关文章
- 1110 Complete Binary Tree (25 分)
1110 Complete Binary Tree (25 分) Given a tree, you are supposed to tell if it is a complete binary t ...
- 【CF438E】The Child and Binary Tree(多项式运算,生成函数)
[CF438E]The Child and Binary Tree(多项式运算,生成函数) 题面 有一个大小为\(n\)的集合\(S\) 问所有点权都在集合中,并且点权之和分别为\([0,m]\)的二 ...
- 2019PAT春季考试第4题 7-4 Structure of a Binary Tree (30 分)
题外话:考试的时候花了一个小时做了27分,由于Siblings这个单词不知道意思,所以剩下的3分就没去纠结了,后来发现单词是兄弟的意思,气哭~~ 这道题的麻烦之处在于如何从一个字符串中去找数字.先首先 ...
- 【LeetCode-面试算法经典-Java实现】【104-Maximum Depth of Binary Tree(二叉树的最大深度)】
[104-Maximum Depth of Binary Tree(二叉树的最大深度)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Given a binary t ...
- LeetCode——Balanced Binary Tree(判断是否平衡二叉树)
问题: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bin ...
- Leetcode 104. Maximum Depth of Binary Tree(二叉树的最大深度)
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- Binary Tree(二叉树+思维)
Binary Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tota ...
- LeetCode 606. Construct String from Binary Tree (建立一个二叉树的string)
You need to construct a string consists of parenthesis and integers from a binary tree with the preo ...
- LeetCode 543. Diameter of Binary Tree (二叉树的直径)
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a b ...
随机推荐
- ubuntu下搭建hadoop平台
终于把单击模式跟伪分布式模式搭建起来了,记录于此. 1.SSH无密码验证配置 因为伪分布模式下DataNode和NameNode均是本身,所以必须配置SSH localhost的无密码验证. 第一步, ...
- LeetCode OJ:Remove Duplicates from Sorted Array II(移除数组中的重复元素II)
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- SQL-left(right,inner) join
left join(左联接) :返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) :返回包括右表中的所有记录和左表中联结字段相等的记录inner join(等值连接) ...
- 《Drools7.0.0.Final规则引擎教程》第4章 4.2 lock-on-active
lock-on-active 当在规则上使用ruleflow-group属性或agenda-group属性的时候,将lock-on-active 属性的值设置为true,可避免因某些Fact对象被修改 ...
- SSH实现远程控制
SSH(Secure Shell)是一种能够提供安全远程登录会话的协议,使用ssh可以在远程linux中执行命令. sshd服务提供两种安全验证的方法: (1)基于口令的安全验证:经过验证帐号与密码即 ...
- 使用Audition录制自己的歌曲
Audition专为在照相室.广播设备和后期制作设备方面工作的音频和视频专业人员设计,可提供先进的音频混合.编辑.控制和效果处理功能.最多混合 128 个声道,可编辑单个音频文件,创建回路并可使用 4 ...
- bzoj 3192 删除物品
Written with StackEdit. Description 箱子再分配问题需要解决如下问题: (1)一共有\(N\)个物品,堆成\(M\)堆. (2)所有物品都是一样的,但是它们有不同的优 ...
- Android开源框架-Annotation框架(以ViewMapping注解为例)
Annotation 分类 1 标准 Annotation 包括Override, Deprecated, SuppressWarnings,标准 Annotation 是指 Java 自带的几个 A ...
- Visual Studio 2013 帮助文档 安装以及如何直接打开
1.在线安装VS2013的MSDN帮助文档 在利用VS2013集成开发环境(IDE)开发程序代码时会经常用到帮助文档,但默认情况下在帮助文档是在线以网页的形式呈现的,当我们不方便上网时就不能够查看帮助 ...
- 【java反射】Class类型的相关操作演练
[一]获取范型接口的实现类的范型类型 (1)范型接口 package org.springframework.context; import java.util.EventListener; publ ...