The order of a Tree

TwinCAT3实战:从零搭建倍福PLC的Modbus-TCP Server 本文详细介绍了如何使用TwinCAT3从零搭建倍福PLC的Modbus-TCP Server,包括环境准备、工程配置、参数设置、客户端连接测试及常见问题排查。通过实战步骤和实用技巧,帮助工程师快速掌握倍福PLC与Modbus-TCP的通信实现,提升工业自动化项目的开发效率。 阅读详情

题目:

As we know,the shape of a binary search tree is greatly related to the order of keys we insert. To be precisely: 
1.  insert a key k to a empty tree, then the tree become a tree with 
only one node; 
2.  insert a key k to a nonempty tree, if k is less than the root ,insert 
it to the left sub-tree;else insert k to the right sub-tree. 
We call the order of keys we insert “the order of a tree”,your task is,given a oder of a tree, find the order of a tree with the least lexicographic order that generate the same tree.Two trees are the same if and only if they have the same shape. 

Input

There are multiple test cases in an input file. The first line of each testcase is an integer n(n <= 100,000),represent the number of nodes.The second line has n intergers,k1 to kn,represent the order of a tree.To make if more simple, k1 to kn is a sequence of 1 to n. 

Output

One line with n intergers, which are the order of a tree that generate the same tree with the least lexicographic. 

Sample Input

4

1 3 4 2

Sample Output

1 3 2 4

 

题意:

输入一串数字,看是否能找到一串数字构成的二叉搜索树和输入数字构成的二叉搜索树相同,同时保证输出的字典序最小。

 

思路:

二叉搜索树有一个性质,先序遍历输出即为从小到大排好的序列。

根据输入的数字构建二叉搜索树,先序遍历输出即可。

 

代码:

#include<stdio.h>
#include<stdlib.h>
int k;
typedef struct note
{
    int data;
    struct note *left;
    struct note *right;
} Note;
typedef struct
{
    Note *root;
} Tree;
void insert(Tree *tree,int value)
{
    Note *note = malloc(sizeof(Note));
    note ->data =value;
    note ->left =NULL;
    note ->right=NULL;
    if(tree->root==NULL)
    {
        tree -> root=note;
    }
    else
    {
        Note *temp= tree ->root;
        while(temp != NULL)
        {
            if(value<temp -> data)
            {
                if(temp->left==NULL)
                {
                    temp->left=note;
                    return;
                }
                else
                {
                    temp=temp ->left;
                }
            }
            if(value>temp->data)
            {
                if(temp->right==NULL)
                {
                    temp->right=note;
                    return;
                }
                else
                {
                    temp=temp->right;
                }
            }
        }
    }
}
void perorder(Note *note)
{
    if(note !=NULL)
    {   if(k==0)
        printf("%d",note -> data);
        else
        printf(" %d",note -> data);
        k++;
        perorder(note -> left);
        perorder(note -> right);
    }
}
int main()
{
    int k;
    int b[110000];
    while(~scanf("%d",&k))
    {
        Tree tree;
        tree.root=NULL;
        int a,i;
        for(i=0; i<k; i++)
        {
            scanf("%d",&a);
            insert(&tree,a);
        }
        k=0;
        perorder(tree.root);
        printf("\n");
    }
    return 0;
}

 

修复Oracle MySQL Server 安全漏洞(CVE-2023-0464) 阅读详情

相关推荐

Web渗透(一)CRLF注入简介

CRLF注入简介1、基础知识2、原理分析3、漏洞挖掘4、防御手段5、CRLF Payload: 1、基础知识 HTTP报文结构 从上图可以看到:HTTP报文由三部分组成:状态行、首部、主体。 可以看到状态行和首部中的每行都是以回车符(\r,%0d,CR)和换行符(\n,%0a,LF)结束。 十六进制编码分别为0x0d和0x0a,URL编码为%0D和%0A 这是因为HTTP规范中行应该使用CRLF结束。另外,首部和主体由两个CRLF分隔。 2、原理分析 CRLF是 “ 回车+换行 ”(\r\n)的简称。

weixin_39157582的博客 6814

The order of a Tree(二叉树的先序遍历)

二叉树的先序遍历

riversu 644

三相电路小白必看:正弦量向量表示法保姆级教程(附欧拉公式推导)

本文为电气工程初学者详细解析了三相电路中正弦量的向量表示法,即相量法。通过几何直观和欧拉公式推导,阐明如何将时变正弦量转化为静态复平面向量进行运算,并利用平行四边形法则简化同频正弦量的加减计算。文章结合Python代码进行可视化验证,帮助读者牢固掌握这一分析交流电路的核心工具。

linux6sysadmin的博客 992

The order of a Tree (二叉搜索树+先序遍历)

As we know,the shape of a binary search tree is greatly related to the order of keys we insert. To be precisely:  1.  insert a key k to a empty tree, then the tree become a tree with  only one node;  ...

一个和代码打交道の小孩 2111

SAP SD 顾问面试问题 consultant interview questionnaire

以下是我个人目前面试团队 SD顾问问题的小结,希望对大家有所帮助, 也可能有回答错误的地方,希望同行不吝赐教。 也希望各位顾问们讲你们遇到的一些面试问题做个跟贴,方便大家共同进步,谢谢。   面试问题清单:  一、销售订单类型影响: 可用性检查,交货类型,输出,信贷,定价,需求,报表,合作伙伴,文本,不完整日志,交货开票,订单开票,公司间开票,统计组,屏幕顺序组,参数文件...

weixin_33825683的博客 1808

CS1237卡尔曼滤波实战:如何用24位ADC实现电子秤级精度?

本文详细介绍了如何利用CS1237 24位ADC芯片结合卡尔曼滤波算法实现电子秤级精度测量。通过解析CS1237硬件特性、卡尔曼滤波原理及STM32驱动优化,提供了一套完整的解决方案,包括多通道支持、驱动代码实现和性能调优技巧,适用于工业测量和嵌入式开发领域。

linux的博客 1086

The order of a Tree( 树的顺序)

As we know,the shape of a binary search tree is greatly related to the order of keys we insert. To be precisely: 1.insert a key k to a empty tree, then the tree become a tree with only one node;...

shiuxin的博客 648

YOLOv8魔改系列:将CIoU替换成Wise-IoU,飞速涨点

将YOLOv8中CIoU替换成Wise-IoU,实现飞速涨点

qq_66386046的博客 2678

The order of a Tree (前序遍历)

As we know,the shape of a binary search tree is greatly related to the order of keys we insert. To be precisely:  1.  insert a key k to a empty tree, then the tree become a tree with  only one node;  ...

自渡的博客 589

Spring AI Alibaba 项目源码学习(九)-其他继承BaseAgent

本文分析了Spring AI Alibaba Agent Framework中的A2aRemoteAgent实现,主要特点包括: 实现了Agent间的远程调用能力,支持分布式部署 核心组件包括AgentCard封装元数据、A2aNodeActionWithConfig处理调用逻辑、AgentCardProvider提供卡片管理 支持流式调用和状态共享机制 采用Builder模式构建Agent实例 通过指令传递实现Agent间通信 关键流程包括状态提取、请求构建、远程调用和状态更新四个步骤,形成Agent

819

【纯干货分享】常用高速接口眼图模板合集

文章汇集了常见的高速接口的信号眼图测试模板技术要求,比如,LPDDR5/4、PCIe 5.0/4.0、USB、MIPI等等,方便工程师快速进行查询和使用。

一只豌豆象的博客 3116

The order of a Tree(二叉树)

Problem Description As we know,the shape of a binary search tree is greatly related to the order of keys we insert. To be precisely: insert a key k to a empty tree, then the tree become a tree with only one node; insert a key k to a nonempty tree, if k is

fatsnake_piao的博客 451

EtherCAT总线运动控制学习笔记(RXXW_Dor)

说到总线控制,就要说到报文、对象字典、PN通信我们大部分会说报文,EtherCAT通信我们常说对象字典,叫法不一样,但是原理基本一致,下面我们简单认识下上面是对象字典。

RXXW_Dor的博客 5425

HDU3999-The order of a Tree

As we know,the shape of a binary search tree is greatly related to the order of keys we insert. To be precisely: insert a key k to a empty tree, then the tree become a tree with only one node; insert...

weixin_43357583的博客 173

深度学习工具包 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")

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

HDU The order of a Tree

原文链接 http://acm.hdu.edu.cn/showproblem.php?pid=3999 

自由女神 580

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

HDU3999:The order of a Tree

Problem Description As we know,the shape of a binary search tree is greatly related to the order of keys we insert. To be precisely: 1.  insert a key k to a empty tree, then the tree become a tree w

ACM!荣耀之路! 2066

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

HDU 3999 The order of a Tree 二叉树

二叉树的先序遍历

NeWnIx 820

hdu 3999 The order of a Tree

题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3999 The order of a Tree Description As we know,the shape of a binary search tree is greatly related to the order of keys we insert. To be preci...

dong12276的博客 95
上一篇: Trees on the level
下一篇: Tree
admin__
博客等级 码龄8年 3粉丝 79原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值