当前位置:网站首页>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;
}
边栏推荐
- Automatic Multi-Organ SegmVentation on Abdominal CT With Dense V-Networks
- L2-031 深入虎穴 (25 分)
- Sublime Text3 set to run your own makefile
- manacher
- Summary of PHP memory horse technology research and killing methods
- 在Activity外使用startActivity()方法报错原因与解决办法
- Alibaba cloud firewall configuration, multiple settings (iptables and firewall)
- EDA and VHDL question bank
- Leetcode MySQL database topic 177
- Codeforces Round #645 (Div. 2)
猜你喜欢
随机推荐
HDU 6778 Car (分组枚举-->状压 dp)
The collapsing "2.3 * 10 = 22" produced by multiplying float and int
manacher
PHP内存马技术研究与查杀方法总结
2019.10.27训练总结
GSOAP example - calc
力扣85题最大矩形
A 3D Dual Path U-Net of Cancer Segmentation Based on MRI
指针数组、数组指针和传参的相关问题
Flutter 基础组件之 ListView
Automatic Multi-Organ SegmVentation on Abdominal CT With Dense V-Networks
Flutter 基础组件之 Image
Leetcode MySQL database topic 177
Function pointer, function pointer array, calculator + transfer table, etc
Codeforces Round #652 (Div. 2)
520 钻石争霸赛 2021
图片验证码控件
JVM之对象的内存布局
Summary of PHP memory horse technology research and killing methods
A method of creating easy to manage and maintain thread by C language









