POJ2309 -- BST
找找规律,实际上是二分查找的过程,只要找到了mid与输入的n相同的话,直接输出left和right就可以了。
代码如下:
#include <iostream>
using namespace std; long long getroot(int n)
{
long long root = ;
while(root* <= n)
root *= ;
return root;
} int main()
{
int T;
cin>>T;
while(T --)
{
long long n,root;
cin>>n;
root = getroot(n);
long long left = , right = *root - ;
long long mid = (left + right)/;
while(mid != n)
{
if(mid > n) right = mid - ;
if(mid < n) left = mid + ;
mid = (right + left)/;
} cout<<left<<" "<<right<<endl; }
return ;
}
POJ2309 -- BST的更多相关文章
- [LeetCode] Delete Node in a BST 删除二叉搜索树中的节点
Given a root node reference of a BST and a key, delete the node with the given key in the BST. Retur ...
- [LeetCode] Serialize and Deserialize BST 二叉搜索树的序列化和去序列化
Serialization is the process of converting a data structure or object into a sequence of bits so tha ...
- [LeetCode] Largest BST Subtree 最大的二分搜索子树
Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest mea ...
- [LeetCode] Inorder Successor in BST 二叉搜索树中的中序后继节点
Given a binary search tree and a node in it, find the in-order successor of that node in the BST. No ...
- [LeetCode] Kth Smallest Element in a BST 二叉搜索树中的第K小的元素
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Not ...
- 二叉排序树(BST)创建,删除,查找操作
binary search tree,中文翻译为二叉搜索树.二叉查找树或者二叉排序树.简称为BST 一:二叉搜索树的定义 他的定义与树的定义是类似的,也是一个递归的定义: 1.要么是一棵空树 2.如果 ...
- Leetcode Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Not ...
- 标准BST二叉搜索树写法
本人最近被各种数据结构的实验折磨的不要不要的,特别是代码部分,对数据结构有严格的要求,比如写个BST要分成两个类,一个节点类,要给树类,关键是所以操作都要用函数完成,也就是在树类中不能直接操作节点,需 ...
- Leetcode 230. Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Not ...
随机推荐
- SQL2005 : 如何在SQL Server Profiler (事件查看器)中 跟踪查看死锁恢复
SQL Profiler 通过 SQL Profiler 工具程序,可监控应用程序如何访问数据库引擎.普通来说,当系统性能需要优化或是应用程序对数据库访问的结果不合预期,都可以使用该工具确认视图问题所 ...
- ReorderList 的使用
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> ...
- Markdown中插入数学公式
如果想复杂使用的话,百度Latex公式,找些看一下. 使用MathJax引擎 大家都看过Stackoverflow上的公式吧,漂亮,其生成的不是图片.这就要用到MathJax引擎,在Markdown中 ...
- su和su-命令的本质区别
su命令和su -命令最大的本质区别就是:前者只是切换了root身份,但Shell环境仍然是普通用户的Shell: 而后者连用户和Shell环境一起切换成root身份了.只有切换了Shell环境才不会 ...
- mybatis oracle insert 返回新增的主键值
<insert id="insertVmsTemplatePlayItem" parameterType="VmsTemplatePlayItem"> ...
- CyclicBarrier类合唱演绎
package a.jery; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.ExecutorServi ...
- python学习笔记(一)
1. BeautifulSoup是一个很好用的Python写的一个HTML/XML的解析器,它可以处理不规范标记并生成剖析树(parse tree).Beautifulsoup可以对便签Object进 ...
- nmap十条常用命令行格式
1) 获取远程主机的系统类型及开放端口 nmap -sS -P0 -sV -O <target> 这里的 < target > 可以是单一 IP, 或主机名,或域名,或子网 - ...
- windows下PHP5.5.6+Apache2.4.7配置
本文主要阐述在windows8及win8.1 环境下搭建PHP5.5.6+Apache2.4.7. 1.软件准备 apache 2.4.7:http://pan.baidu.com/s/1iUPif ...
- Ibatis 测试出SQL
String sql = Brg.Global.Map.BaseBatis.GetRuntimeSql("select_T_JewelleryProductType", _Mode ...