当前位置:网站首页>Stl+ tree
Stl+ tree
2022-06-24 22:00:00 【Weng Weiqiang】
"Code is beautiful and powerful that can changes the world"
--2021.8.23
subject :https://codeforces.com/problemset/problem/675/D
Carelessness : Construct a binary tree , Output... In sequence The parent node corresponding to the input value
Answer key :1. utilize set Sort storage nodes from small to large
2. Consider the situation
AC Code :
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<set>
#include<map>
using namespace std;
const int N = 1e5;
int a[N+1];
int main()
{
a[0] = 0;
int n;
while (scanf("%d", &n) != EOF)
{
set<int>s;
scanf("%d", &a[1]);
s.insert(a[1]);
map<int, int>l, r;// Represents whether there are left and right subtrees
for (int i = 2; i <= n; ++i)
{
if (i > 2) { cout << " "; }
scanf("%d", &a[i]);
set<int>:: iterator add;// Get address
add = s.lower_bound(a[i]);// See if you can find a larger number
if (add == s.end())// It means that we didn't find
{
printf("%d", *(--add));// Just take it as set The right subtree of the maximum in
r[*(add)] = 1;// Mark it as the right node of the parent node
}
else// Find a larger number
{
if (l[*add] == 1)// If the left subtree of the node already exists
{
printf("%d", *(--add));// It is called its position -1 The right subtree of the previous node of
r[*(add)] = 1;
}
else// If the left subtree exists, it is regarded as the left subtree of the node
{
printf("%d", *(add));
l[*(add)] = 1;
}
}
s.insert(a[i]);
}
}
return 0;
}边栏推荐
- Guava中这些Map的骚操作,让我的代码量减少了50%
- These map operations in guava have reduced my code by 50%
- Detailed installation and use of performance test tool wrk
- 双链表实现
- openGauss内核:简单查询的执行
- 数据链路层 && 一些其他的协议or技术
- socket done
- 多路转接select
- 2022 international women engineers' Day: Dyson design award shows women's design strength
- 平衡二叉搜索树
猜你喜欢

Make tea and talk about heroes! Leaders of Fujian Provincial Development and Reform Commission and Fujian municipal business office visited Yurun Health Division for exchange and guidance

The collection of zero code enterprise application cases in various industries was officially released

Opengauss kernel: simple query execution

Binary search tree template

【吴恩达笔记】多变量线性回归
![在每个树行中找最大值[分层遍历之一的扩展]](/img/5b/81ff20b61c0719ceb6873e44878859.png)
在每个树行中找最大值[分层遍历之一的扩展]

排查到解决问题的过程:浏览器突然无法访问网页,错误代码:0x80004005,最终定位:“电脑打开热点,电脑就不能上网了”

Kubernetes 集群中流量暴露的几种方案

Machine learning: linear regression

【吴恩达笔记】卷积神经网络
随机推荐
WMI and PowerShell get TCP connection list
Suspend component and asynchronous component
建木持续集成平台v2.5.0发布
Summary of papers on traveling salesman problem (TSP)
Detailed installation and use of performance test tool wrk
SAP接口debug设置外部断点
Several schemes of traffic exposure in kubernetes cluster
How to resolve the 35 year old crisis? Sharing of 20 years' technical experience of chief architect of Huawei cloud database
栈的两种实现方式
【吴恩达笔记】多变量线性回归
[untitled]
[精选] 多账号统一登录,你如何设计?
传输层 udp && tcp
I really want to send a bunch of flowers
【OpenCV 例程200篇】209. HSV 颜色空间的彩色图像分割
Structured interview of state-owned enterprises and central enterprises employment of state-owned enterprises Modou Interactive Employment Service steward
多线程收尾
专科出身,2年进苏宁,5年跳阿里,论我是怎么快速晋升的?
St Table + two points
Practice of hierarchical management based on kubesphere