POJ2309 BST(树状数组)

贴一个类岛娘的头文件 其实一大半都是岛娘的,好吧几乎都是。。。 出处——岛娘的头文件 #define LOCAL /** ` Micro Mezzo Macro Flation -- Overheated Economy ., Ver 0.1 **/ #include #include #include #include #include #include #include #include # 阅读详情

BST
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 9098 Accepted: 5552

Description

Consider an infinite full binary search tree (see the figure below), the numbers in the nodes are 1, 2, 3, .... In a subtree whose root node is X, we can get the minimum number in this subtree by repeating going down the left node until the last level, and we can also find the maximum number by going down the right node. Now you are given some queries as "What are the minimum and maximum numbers in the subtree whose root node is X?" Please try to find answers for there queries. 

Input

In the input, the first line contains an integer N, which represents the number of queries. In the next N lines, each contains a number representing a subtree with root number X (1 <= X <= 231 - 1).

Output

There are N lines in total, the i-th of which contains the answer for the i-th query.

Sample Input

2
8
10

Sample Output

1 15
9 11



给你n个数字,每个数字为根构成题目所示的树,输出每棵树的最小值和最大值。


lowbit函数的应用,二进制中最靠后1和0组成的数字。对以x为根的子树上的所有结点编号除lowbit那一位均与x相同。不在该子树上结

点的编号的最高位均与x不同。


AC代码:


#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
int n, x;
int lowbit(int x)
{
	return x & (-x);
}
int main(int argc, char const *argv[])
{
	scanf("%d", &n);
	while(n--) {
		scanf("%d", &x);
		printf("%d %d\n", x - lowbit(x) + 1, x + lowbit(x) - 1);
	}
	return 0;
}


二维树状数组学习之二:练习POJ 1195 NULL 博文链接:https://128kj.iteye.com/blog/1746750 立即下载

相关推荐

手把手教你用ES8311芯片搞定智能音箱TTS播放(附完整寄存器配置清单)

本文详细介绍了如何使用ES8311音频编解码芯片实现智能音箱TTS播放功能,包括芯片特性、硬件连接、寄存器配置及调试技巧。通过完整的寄存器配置清单和实战经验,帮助开发者快速掌握ES8311在智能音箱中的应用,优化音频输出质量和低功耗设计。

weixin_42567497的博客 558

poj 2309-BST解题报告

链接:http://poj.org/problem?id=2309 这道题是给出了这样的结构的一棵树,要找的是给一个根的值,找出这个树节点的最大值和最小值。我们可以很容易观察到每个节点所处的高度是和其包含的2的个数所决定的,而且其左儿子的递减速度为4-2-1,右儿子的递增素速度为4-2-1,那么我们只要将其二进制的最后一个1挪到最后一位,就可得到其最小值,将其二进制的最后一个1后面所有...

weixin_30484247的博客 153

WPS JS宏智能识别代码段并设置样式(完整可用版)

之前,我们已经经历了多次迭代,解决了许多问题,比如识别代码块、处理多行导入、调整样式等。现在他们需要一份全面的文档来解释整个代码的结构和工作原理。(5)智能行分析(含URL和注解检测优化)function analyzeLineEnhanced(rawText,trimmedText,codeSymbols,codePatterns, singleLinePatterns)该解决方案在保持高性能的同时,提供了良好的可扩展性,能够适应不同组织的代码规范需求,是WPS生态中专业文档处理的创新实践。

搏博的专栏 1822

POJ 2309 BST

题目链接: http://poj.org/problem?id=2309 难度级别: 2 BST Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7685   Accepted: 4654 Description Consi

青瑟只鸟的专栏 1755

Cesium实战:5分钟搞定离线地图与地形加载(附避坑指南)

本文详细介绍了Cesium在内网环境下的离线部署实战方案,重点解决了影像与地形数据的本地加载问题。通过逐步指导项目配置、本地瓦片与自定义地形数据的处理,并优化相机控制体验,帮助开发者快速构建安全、高效的三维地球应用,避免常见的401错误与加载失败陷阱。

weixin_30632089的博客 281

Kalibr标定避坑指南:如何用AprilGrid板快速完成双目IMU标定

本文详细介绍了使用AprilGrid板进行Kalibr双目IMU联合标定的实战技巧,包括标定工具选型、数据采集优化、标定流程及结果验证。通过AprilGrid板的唯一标识性和抗遮挡优势,结合IMU静止标定和运动激励设计,显著提升标定精度。文章还提供了常见报错处理和高级优化技巧,帮助开发者高效完成传感器标定。

sunny的博客 282

POJ 2309 BST 题解

POJ 2309 BST 题解,思路与标程

m0_69349401的博客 248

从按键开机到I2C隔离:手把手拆解一个智能硬件项目里的MOS管实战配置

本文详细解析了智能硬件项目中MOS管的实战配置,从按键开机电路到I2C总线隔离,全面覆盖电源管理和信号隔离的关键技术。通过PMOS+NMOS组合方案实现可靠的开机功能,并采用双NMOS方案优化I2C通信隔离,提升系统稳定性和信号质量。

weixin_28691741的博客 326

基础训练(四)BST二叉排序树

BST(poj:2309) 题目传送门 Time Limit: 1000MS Memory Limit: 65536K Description Consider an infinite full binary search tree (see the figure below), the numbers in the nodes are 1, 2, 3, … In a subtree whose root node is X, we can get the minimum number in this su

WeChat:A15047825994 317

微弱电流检测放大器PCB布线布局设计

微弱电流检测放大器PCB布线布局设计的注意事项,保护环的概念和相关设计。

ydgd118的博客 1万+

电压跟随器在ADC采样电路中的作用分析

电压跟随器在ADC采集系统中扮演关键角色,它能解决分压电路因ADC输入阻抗导致的电压误差问题。通过运放构成的电压跟随器可隔离信号源与负载,保证采样精度,尤其适用于高阻抗传感器或高速采样场景。工程应用中需注意运放带宽、轨对轨输出能力及抗干扰设计。合理使用电压跟随器能显著提升信号完整性,在复杂电子系统中成为不可或缺的"信号桥梁。

硬核科技 655

BST poj2309(树状数组lowbit)

题目链接: BST 题目很好理解,不再赘述题意 思路: 看很多文章都说是树状数组,但是我仔细想了想,发现跟树状数组还是有区别的,只能说跟数状数组类似,但是不是树状数组 利用树状数组中的lowbit来计算 这个二叉树的节点值,从左向下每个节点减的都是当前节点值的lowbit() / 2,那么最后减的总数不就是,给定根节点的lowbit() - 1,同理,从右往下走,加的是根节点的lowbit() - 1,可以拿笔将其转化为二进制试一试,这个值就是根节点lowbit() / 2 的值在二进制的位置然后一直到0

CUCUC1的博客 235

【图像超分】论文精读:Accelerating the Super-Resolution Convolutional Neural Network(FSRCNN)

作为应用于图像超分辨率 (SR) 的成功深度模型,超分辨率卷积神经网络 (SRCNN) [1,2] 在速度和恢复质量方面都比以前的手工制作的模型表现出更好的性能。然而,高计算成本仍然阻碍了它的实际使用,这需要实时性能(24 fps)。在本文中,我们旨在加速当前的 SRCNN,并提出了一种紧凑的沙漏形 CNN 结构,以实现更快和更好的 SR。我们从两个方面重新设计了SRCNN结构。首先,我们在网络末端引入了一个反卷积层,然后将映射直接从原始低分辨率图像(无插值)学习到高分辨率图像。其次,我们通过在映射之前缩小

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 1万+

【树状数组】POJ 2309 BST

树状数组第一步,了解如何获取一个整数的最后一位是1的数

小do在努力 646

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

POJ2309BST(树状数组)

BST Time Limit:1000MS Memory Limit:65536K Total Submissions:9182 Accepted:5613 Description Consider an infinite full binary search tree (see the figure below),...

apk6909的博客 98

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

poj 2309 BST 使用树状数组的lowbit

如果领悟了树状数组中的lowbit,这道题就是极其简单的,最底层都是奇数,用lowbit(x)寻找x的父亲,然后x的父亲-1就是最大数 至于lowbit是如何计算的嘛,寻找x的父亲,其实就是x+2^x的二进制末尾0的个数。 #include #include using namespace std; typedef long long ll; ll lowbit(int x){ re

代码随想录 1059

POJ 2309 BST(树状数组)

我只想说,对于了解并且会树状数组的人来说,别以为换了个图我们就认不出来你是个树状数组=。= 对于不太了解的,请见【转】搞懂树状数组 var t,n,x :longint; begin read(t); while (t>0) do begin dec(t); read(n); x:=n-(n and

Eirlys的博客 428

POJ2309BST【树状数组的理解】

大意: 对于这个树 告诉你一个节点问这个节点下的最小值和最大值   分析: 这个题考查对于树状数组的理解,   每个节点的前一个节点都是依次向前的 比如 10--8--4--2--1 后一个节点都是一次往后的比如10--12--16…… 那么我们观察发现每个节点的最小值都是他爹+1,最大值都是他妈-1   代码: 1 #include 2 #include

zhanzhaozhangxiaoyi的专栏 258

POJ 2309 BST (树状数组)

BST Time Limit:1000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64u SubmitStatus Description Consider an infinite full binary search tree (see the figure below), the numbers in

sxk 862

POJ 2309 BST 树状数组基本操作

Description Consider an infinite full binary search tree (see the figure below), the numbers in the nodes are 1, 2, 3, .... In a subtree whose root node is X, we can get the minimum number in this

靖空间 1840

POJ2309--BST--树状数组

Description Consider an infinite full binary search tree (see the figure below), the numbers in the nodes are 1, 2, 3, .... In a subtree whose root node is X, we can get the minimum number in this su

SCUT_Pein 993

[POJ](2309)BST ---- 树状数组lowbit

题目传送门 做法:其实还是从题目中给的这棵二叉搜索树找规律,我们发现最小的其实就是 x-lowbit(x)+1,即树状数组中x位置所维护的区间的左端点,接机推出最大即x+lowbit(x)-1; AC代码: #include &lt;iostream&gt; #include &lt;cmath&gt; #include &lt;cstdio&gt; #include &lt;algori...

WangMeow --- ᶘ ᵒᴥᵒᶅ ฅ^•ﻌ•^ฅ 236
上一篇: POJ3321 Apple Tree(树状数组 + dfs + 线性表)
下一篇: Codeforces Round #302 (Div. 1) 543A Writing Code(dp)
GKHack
博客等级 码龄11年 48粉丝 291原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值