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

SampleInput

4
1 3 4 2

SampleOutput

1 3 2 4

刷些水题打发时间。。

 1 #include<algorithm>
 2 #include<iostream>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<vector>
 7 #include<map>
 8 #include<set>
 9 using std::cin;
10 using std::cout;
11 using std::endl;
12 using std::find;
13 using std::set;
14 using std::map;
15 using std::pair;
16 using std::vector;
17 using std::multiset;
18 using std::multimap;
19 #define sz(c) (int)(c).size()
20 #define all(c) (c).begin(), (c).end()
21 #define iter(c) decltype((c).begin())
22 #define cls(arr,val) memset(arr,val,sizeof(arr))
23 #define cpresent(c, e) (find(all(c), (e)) != (c).end())
24 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
25 #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
26 #define pb(e) push_back(e)
27 #define mp(a, b) make_pair(a, b)
28 const int Max_N = 100100;
29 typedef unsigned long long ull;
30 struct Node {
31     int v;
32     Node *ch[2];
33     inline void setc(int _v, Node *p) {
34         v = _v;
35         ch[0] = ch[1] = p;
36     }
37 };
38 struct BST {
39     Node *root, *null, *tail;
40     Node stack[Max_N];
41     inline void init() {
42         tail = &stack[0];
43         null = tail++;
44         null->setc(0, NULL);
45         root = null;
46     }
47     inline Node *newNode(int v) {
48         Node *p = tail++;
49         p->setc(v, null);
50         return p;
51     }
52     inline void insert(Node *&x, int v) {
53         if (x == null) { x = newNode(v); return; }
54         insert(x->ch[v > x->v], v);
55     }
56     inline void dfs(vector<int> &res, Node *x) {
57         if (x != null) {
58             res.pb(x->v);
59             dfs(res, x->ch[0]);
60             dfs(res, x->ch[1]);
61         }
62     }
63     inline void insert(int v) {
64         insert(root, v);
65     }
66     inline void go() {
67         vector<int> res;
68         dfs(res, root);
69         int n = sz(res);
70         rep(i, n) printf("%d%c", res[i], i < n - 1 ? ' ' : '\n');
71     }
72 }bst;
73 int main() {
74 #ifdef LOCAL
75     freopen("in.txt", "r", stdin);
76     freopen("out.txt", "w+", stdout);
77 #endif
78     int n, v;
79     while (~scanf("%d", &n)) {
80         bst.init();
81         rep(i, n) scanf("%d", &v), bst.insert(v);
82         bst.go();
83     }
84     return 0;
85 }
View Code

 

转载于:https://www.cnblogs.com/GadyPu/p/4572796.html

Python爬虫实战:用Selenium+ChromeDriver批量抓取政府网站政策文件(附完整代码) 本文详细介绍了使用Python的Selenium和ChromeDriver进行政府网站政策文件批量抓取的实战技巧。从环境配置、动态页面元素定位到分页机制破解和反爬虫策略,提供了完整的解决方案和代码示例,帮助开发者高效获取结构化政策数据。 阅读详情

相关推荐

LayaBox CommandBuffer描边使用详细

项目需要使用LayaBox做一个给3D物体动态描边的一个功能,前前后后踩了一些坑算是把这个东西给做出来了把我改好的代码贴上,分享给大家。 (1)想要使用描边你的引擎版本必须 >=2.9.0 (2)你必须下载 Laya官方的BlurShader库才能使用这个功能,下载地址:https://github.com/layabox/layaair-demo/tree/master/h5/3d/ts/LayaAir3D_PostProcess/BlurShader 下载完之后把BlurShader放到自己项目的

小智队长 1732

RK3588 VPU性能调优实战:如何开启内核调试打印,精确测量每帧编解码耗时?

本文详细介绍了RK3588 VPU性能调优的实战方法,重点讲解如何开启内核调试打印并精确测量每帧编解码耗时。通过配置内核调试节点、捕获调试日志以及分析性能数据,开发者可以优化硬件编解码器的性能,提升视频处理效率。文章还提供了常见优化方向和高级调试技巧,帮助解决实际开发中的性能瓶颈问题。

weixin_30394669的博客 296

VLM,VLA,VLN的区别与联系

VLM 提供了理解世界的“眼睛和大脑”,VLN 赋予了这个智能体在空间中“移动的双腿”,而 VLA 则进一步赋予了它“灵巧的双手”来改变世界。三者共同构成了一个完整具身智能体的核心能力模块。

l0409044222的博客 1309

rk3588音视频硬件编解码介绍

ffmedia硬件音视频编解码

weixin_43802726的博客 6182

RunHarmony报错解析:如何解决data.use与cell.embeddings维度不匹配问题

本文深入解析了单细胞数据分析中RunHarmony函数报错'non-conformable arguments'的根源,即data.use与cell.embeddings矩阵维度不匹配。核心原因是assay(如RNA与integrated)错配导致细胞ID或数量不一致。文章提供了三种解决方案:最推荐显式指定assay.use参数,也可设置project.dim=FALSE或统一数据环境,并给出了最佳实践指南以避免此类错误。

weixin_29093017的博客 575

数据分享|1961-2017年中国0.25°×0.25° 逐日地表水文数据集(VIC-CN05.1)

其中,全球径流中心(University of New Hampshire and Global Runoff Data Centre, UNH/GRDC)的复合产流场集成了观测的河道径流和水量平衡模式模拟的地表和地下径流,常被用来评估模拟的径流。在长白山、海北灌丛和千烟洲通量站,模拟与观测的逐月潜热通量的平均NSE为0.61。VIC-CN05.1受益于较准确的大气驱动场、先进的地表水文参数化方案以及更真实丰富的土壤信息,可作为中国水文气象研究的参照数据,用于陆面模式的评估和长期的趋势分析等。

J_Giser的博客 1830

2020-12-21

第一篇测试文章LeTex 测试Logistic Regression 损失函数 LeTex 测试 加粗测试 Logistic Regression 损失函数 floss=∑i=0myi(1−h(xi))+(1−yi)h(xi) f_{loss} = \sum_{i = 0}^m y_i(1-h(x_i)) + (1-y_i)h(x_i) floss​=i=0∑m​yi​(1−h(xi​))+(1−yi​)h(xi​) ...

KazeHelloWorld的博客 224

一张图讲透银行个人外汇业务逻辑和实操

个人外汇业务主要分为结售汇和外币兑换两类,前者满足日常跨境需求,后者因投机属性多数银行已暂停。业务核心是利用汇率波动实现货币兑换,满足支付或投资需求。交易涉及客户分类、主流币种、多种渠道和汇率计算规则,需区分直接/间接标价法判断汇率走势。银行通过"货币兑换"科目核算损益,采用期末折算确认盈亏。监管要求包括5万美元年度额度、合法渠道、真实性原则及大额申报等。随着跨境金融数字化发展,掌握基础逻辑和合规要求是安全参与外汇业务的关键。

银行信息系统应用架构详解 288

视觉推理新杀器!英特尔新一代VPU性能翻10倍,反超英伟达

点击我爱计算机视觉标星,更快获取CVML新技术本文转自新智元。新智元报道来源:venturebeat编辑:肖琴【新智元导读】英特尔今天宣布首款AI芯片Nervana神经网络处理器...

我爱计算机视觉 888

华为FusionCompute之计算虚拟化

华为FusionCompute之虚拟化

jks212454的博客 2452

数据结构课程设计C/C++版--美团餐馆预定信息的管理与分析 1 2

本关任务:从文件user.txt中读取用户信息,包括账号、密码、联系方式等,创建一个用户信息的顺序表,根据账号判断顺序表中是否存在当前用户。如果存在,则添加失败。否则,判断输入的用户信息中是否有非法输入,若有则添加失败,否则将该用户作为新结点,按顺序插入到顺序表的相应位置,并将用户顺序表写入user.txt中。本关任务:从文件user.txt中读取用户信息,存入顺序表中。输入待查找的用户账号,调用折半查找算法判断用户顺序表中是否存在该用户的账号信息。如果存在,则返回其在顺序表中的位置,说明查找成功;

m0_62222486的博客 4934

HDU3999 The order of a Tree

HDU3999 The order of a Tree 复习二叉树ing 题目地址 创建一个二叉树,小于根的数放左子树,大于的放右子树,输出和这个数相同的最小字典序,嘛,翻译解释的肯定比我解释的好。 要字典序最小,正好为树的前序遍历,前序遍历并输出就好了。 代码如下: #include<bits/stdc++.h> #define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; typed

fatekingsama的博客 176

Camera2Demo

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

HDU 3999 The order of a Tree

今天回学校了,准确的说是昨天回来的,今天第一天来机房,暑假搞的东西欠下的债不少,然后补补题 发现是个大水题 The order of a Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4235 Accepted Submission(s): 2151 Problem Description As we know,the .

苦鬼·。 231

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

hdu 3999 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 t

Vision 374

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

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

HDU 3999 The order of a Tree 二叉树

二叉树的先序遍历

NeWnIx 820

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

hdu 3999The order of a Tree

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3999 本题为简单二叉排序树,先按排序树创建树,然后先序遍历二叉树,输出的时候最后一个数字后面没有空格。 数组实现:   #include #include #define N 100005 int tree[N],left[N],right[N],a[N],num,flg;//tree数

为编程而生 732

HDU - 3999 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;  ...

GJLfly的博客 188

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

bayleexu 509

The order of a Tree hdu3999 二叉搜索树

题目链接: hdu3999 The order of a Tree 题意: 给一个二叉搜索树的序列,求输出可以构成这个二叉搜索树的且满足字典序最小的插入序列 找了一个比较具体描述怎么根据序列建立二叉搜索树的 图片来自:https://blog.youkuaiyun.com/qq_39290830/article/details/85197994 思路: 首先,根据输入键的顺序,构造对应的二叉搜索树;然后,前序遍历这棵二叉树,得出的 树的顺序就是以最小的字典序生成的相同形状的树。 #include <iostre

CUCUC1的博客 268

The order of a Tree 【HDU - 3999 】

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

Meant_To_Be的博客 302
上一篇: poj 2299 Ultra-QuickSort
下一篇: hdu 2203 亲和串
dong12276
博客等级 码龄13年 0粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值