当前位置:网站首页>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
- Sublime Text3 set to run your own makefile
- In XML layout, the button is always displayed on the top layer
- 2019.10.20 training summary
- Function pointer, function pointer array, calculator + transfer table, etc
- Flutter 基础组件之 ListView
- Caused by: org.apache.xerces.impl.io.MalformedByteSequenceException: Invalid byte 3 of 3-byte UTF-8
- 山科 的C语言2018练习题(电信)
- Leetcode MySQL database topic 177
- 详细分析PBot挖矿病毒家族行为和所利用漏洞原理,提供蓝军详细防护建议
猜你喜欢

指针数组、数组指针和传参的相关问题

使用Rancher搭建Kubernetes集群

Alternative implementation of Scrollview pull-down header amplification

Simulation problem of two stacks

Flutter 基础组件之 Image

TLAB of JVM

Automatic Multi-Organ SegmVentation on Abdominal CT With Dense V-Networks

Codeforces Round #645 (Div. 2)

Application of keil5 integrated development environment for single chip microcomputer

container
随机推荐
RecyclerView 粘性(悬浮)头部
2019.10.16训练总结
JVM之 MinorGC、 MajorGC、 FullGC、
Automatic Multi-Organ SegmVentation on Abdominal CT With Dense V-Networks
Codeforces Round #657 Div. 2
Application of keil5 integrated development environment for single chip microcomputer
JVM之虚拟机栈之动态链接
Sixteen system counter and flow lamp
2019.10.23 training summary
L2-025 分而治之 (25 分)
完全二叉树的权值 递归做法 ——最后的编程挑战
Flutter 基础组件之 GridView
2019.10.27训练总结
Dynamic linking of virtual machine stack of JVM
Constructing SQL statements by sprintf() function in C language
Leetcode MySQL database topic 176
2019.10.27 training summary
Ural1517 freedom of choice [suffix array: longest common continuous substring]
Codeforces Round #652 (Div. 2)
2019.11.3学习总结