找找规律,实际上是二分查找的过程,只要找到了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的更多相关文章

  1. [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 ...

  2. [LeetCode] Serialize and Deserialize BST 二叉搜索树的序列化和去序列化

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  3. [LeetCode] Largest BST Subtree 最大的二分搜索子树

    Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest mea ...

  4. [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 ...

  5. [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 ...

  6. 二叉排序树(BST)创建,删除,查找操作

    binary search tree,中文翻译为二叉搜索树.二叉查找树或者二叉排序树.简称为BST 一:二叉搜索树的定义 他的定义与树的定义是类似的,也是一个递归的定义: 1.要么是一棵空树 2.如果 ...

  7. 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 ...

  8. 标准BST二叉搜索树写法

    本人最近被各种数据结构的实验折磨的不要不要的,特别是代码部分,对数据结构有严格的要求,比如写个BST要分成两个类,一个节点类,要给树类,关键是所以操作都要用函数完成,也就是在树类中不能直接操作节点,需 ...

  9. 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 ...

随机推荐

  1. Openstack Neutron L2 Population

    Why do we need it, whatever it is? VM unicast, multicast and broadcast traffic flow is detailed in m ...

  2. Apache + PHP 环境搭建

    环境: Win7 64位 php-5.6.19-Win32-VC11-x64 httpd-2.4.18-win64-VC11 下载地址: php:  http://windows.php.net/do ...

  3. 钉钉的收费 [钉钉深圳研发团队 denny/2016.01.06/ 59888745@qq.com]

    普通用户(个人) 团队 企业 1.免费额度为每月通话100分钟.每天发DING 5次. 1.   每月通话300分钟,每天发DING   10次. 2.   群组最多可达1500人 1.   该公司所 ...

  4. winXP下安装opensshd服务

    1)参考如下帖子:http://blog.chinaunix.net/uid-23187544-id-2527564.html http://wuhuizhong.iteye.com/blog/122 ...

  5. Chap5: question 35 - 37

    35. 第一个只出现一次的字符 char firtNotRepeat(char *s) { if(s == NULL) return 0; int i = 0; while(s[i] != '\0') ...

  6. Android 实现多行文本跑马灯效果

    Android TextView 实现跑马灯的效果很简单,只要加三个属性就可以了. android:ellipsize="marquee" android:focusable=&q ...

  7. 教你用Ossim平台检测网络的Shellcode攻击

    教你用Ossim平台检测网络的Shellcode攻击行为 教程: http://www.tudou.com/programs/view/-hxTm0q1tDY/ 以下是视频截图: 更多视频内容: 本文 ...

  8. Maven实战(二)构建简单Maven项目

    上一节讲了maven的安装和配置,这一节我们来学习一下创建一个简单的Maven项目 1. 用Maven 命令创建一个简单的Maven项目 在cmd中运行如下命令: mvn archetype:gene ...

  9. python学习笔记:文件操作和集合(转)

    转自:http://www.nnzhp.cn/article/16/ 这篇博客来说一下python对文件的操作. 对文件的操作分三步: 1.打开文件获取文件的句柄,句柄就理解为这个文件 2.通过文件句 ...

  10. LeftoverDataException.

    在用java poi 3.8操作excel的时候,在打开一个已有excel文件时,有时候会报错: org.apache.poi.hssf.record.RecordInputStream$Leftov ...