当前位置:网站首页>Weight recursion of complete binary tree -- the last programming challenge
Weight recursion of complete binary tree -- the last programming challenge
2022-06-29 10:13:00 【Momo 623】
utilize k*2+1 and k*2
Every time I look for k My son , Record the number of layers when searching
Finally, we need to make a circular judgment
notes : Judgment can no longer dfs In the middle of Because the final answer is likely to be the result of a certain period of time on a certain layer Not the end result
#include <iostream>
#include <algorithm>
using namespace std;
const int n = 100005;
typedef long long ll;
int t[n];
int ans = 0;
ll maxt = -1e35;
int lcnt;
ll level[n];
int N;
void dfs(int k, int l)
{
if (k > N)
return;
// How many layers of records
lcnt = max(l, lcnt);
// Every time you join
level[l] += t[k];
dfs(k * 2, l + 1);
dfs(k * 2 + 1, l + 1);
}
int main()
{
cin >> N;
for (int i = 1; i <= N; i++)
scanf("%d", &t[i]);
dfs(1, 1);
for (int i = 1; i <= lcnt; i++)
{
if (maxt < level[i])
maxt = level[i], ans = i;
}
printf("%d", ans);
return 0;
}
边栏推荐
- The collapsing "2.3 * 10 = 22" produced by multiplying float and int
- A method of creating easy to manage and maintain thread by C language
- Codeforces Round #657 Div. 2
- Flutter 基础组件之 Image
- JVM四种调用方法的指令
- 在Activity外使用startActivity()方法报错原因与解决办法
- 指针数组、数组指针和传参的相关问题
- L2-025 分而治之 (25 分)
- Setinterval, setTimeout and requestanimationframe
- Leetcode MySQL database topic 180
猜你喜欢

Judgment of points inside and outside polygon

Cisco ASA、FTD和HyperFlex HX的漏洞分析复现

Memory layout of JVM objects

Simulation problem of two stacks

The Stones Game【取石子博弈 & 思维】

Flutter 基础组件之 Image

FreeRTOS (IX) - queue

Image of the basic component of the shutter

A method of creating easy to manage and maintain thread by C language

Gmail: how to quickly read all messages
随机推荐
图片验证码控件
2019.11.20训练总结
Reverse thinking - short story
Causes and solutions of error reporting by using startactivity() method outside the activity
Nacos environmental isolation
Alibaba cloud firewall configuration, multiple settings (iptables and firewall)
Memory layout of JVM objects
L1-009 sum of N numbers (20 points)
Binding mechanism of JVM methods
A 3D Dual Path U-Net of Cancer Segmentation Based on MRI
Flutter 基础组件之 Image
Application of keil5 integrated development environment for single chip microcomputer
六度空间 bfs
Shanke's C language 2018 exercise (Telecom)
弧形 View 和弧形 ViewPager
蛇形填数
Wandering --- 最后的编程挑战
2019-11-10训练总结
Simulation problem of two stacks
Nacos环境隔离