找找规律,实际上是二分查找的过程,只要找到了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. 【python】类中__slots__使用

    __slots__作用:限制类的属性,只给实例绑定任何属性和方法 如果我们想要限制class的属性怎么办?比如,只允许对Student实例添加name和age属性. 为了达到限制的目的,Python允 ...

  2. H5 App开发用WeX5垃圾 试用一周,我果断放弃了wex5

    上个月,和朋友一起参加wex5的分享会,因为对cordova有些了解,始终不相信wex5的广告.五一假期,小试一下,果然不出我所料,有不少坑. 想下载IDE,竟然有1.7G,虽然现在网速快但是文件太大 ...

  3. AttributeTargets 枚举

    AttributeUsage AttributeTargets 在C#的类中,有的类加上了[AttributeUsage(AttributeTargets.Property)]这个是起什么作用的呢?A ...

  4. 自动 点击切换 按钮切换 轮播无缝选项卡 ----原生js

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta name ...

  5. js传递参数中包含+号时的处理方法

    encodeURI(url).replace(/\+/g, '%2B') 例子: $scope.getAnesthesiawaystatistical = function (annual, anes ...

  6. IIS与Apache同时使用80端口

    如果我们在一台服务器即使用IIS作为WEB服务器,同时又想使用Apache作为WEB服务器,那么如何来公用80端口呢? 我们可以使用单IP地址来实现,但是在性能上有损失: 将apache设为使用80端 ...

  7. VPS及LNMP(一)

    1.试用了搬瓦工.interserver.天翼云.网安互联之后,分别写下感受: 前两个是美国服务器,天翼云是国内服务器,网安互联是香港主机. a.搬瓦工非常便宜,512M的1年9.99刀,但是用了之后 ...

  8. POS管理系统之供应商查询

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...

  9. AX2012 审批流流转到已停用的域账号导致审批流停止

    AX 2012 中当审批流流转到某个节点时,如果在该节点的审批人的域账号被停用,审批流将会停止,会报如图的错误: 要解决这个问题,得修改标准功能,需要修改SysWorkflow和SysWorkflow ...

  10. linux grep命令详解

    linux grep命令详解 简介 grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来 ...