当前位置:网站首页>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;
}边栏推荐
- WMI and PowerShell get TCP connection list
- A deep learning model for urban traffic flow prediction with traffic events mined from twitter
- Summary of papers on traveling salesman problem (TSP)
- LeetCode-513. 找树左下角的值
- 【吴恩达笔记】多变量线性回归
- 机器学习:线性回归
- leetcode1720_ 2021-10-14
- [精选] 多账号统一登录,你如何设计?
- 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
- How to refine permissions to buttons?
猜你喜欢

【OpenCV 例程200篇】209. HSV 颜色空间的彩色图像分割

Maximum flow problem

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

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

即构「畅直播」上线!提供全链路升级的一站式直播服务

Fuzhou business office of Fujian development and Reform Commission visited the health department of Yurun university to guide and inspect the work

Redis+caffeine two-level cache enables smooth access speed

leetcode_191_2021-10-15

(to be added) games101 job 7 improvement - knowledge you need to know to realize micro surface model
随机推荐
《各行业零代码企业应用案例集锦》正式发布
面试官:你说你精通Redis,你看过持久化的配置吗?
leetcode-201_2021_10_17
SAP接口debug设置外部断点
openGauss内核:简单查询的执行
Collapse code using region
[精选] 多账号统一登录,你如何设计?
(to be added) games101 job 7 improvement - knowledge you need to know to realize micro surface model
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
火狐拖放后,总会默认打开百度搜索,如果是图片,则会打开图片。
Graduation design of phase 6 of the construction practice camp
socket(1)
架构实战营 第 6 期 毕业设计
排查到解决问题的过程:浏览器突然无法访问网页,错误代码:0x80004005,最终定位:“电脑打开热点,电脑就不能上网了”
leetcode_ 191_ 2021-10-15
【OpenCV 例程200篇】209. HSV 颜色空间的彩色图像分割
Transport layer UDP & TCP
TKKC round#3
Machine learning: linear regression
福建省发改委福州市营商办莅临育润大健康事业部指导视察工作