蓝桥杯(3.17 刷真题)

1240. 完全二叉树的权值
P8681 蓝桥杯 2019 省 AB 完全二叉树的权值
AC

java 复制代码
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] res = new int[n+1];
		for(int i=1;i<=n;i++) {
			res[i] = sc.nextInt();
		}
		int cs = 1;
		long MAX = Long.MIN_VALUE;
		int key = 0;
		int t = 1;
		for(int i=1;i<=n;i*=2,cs++,t*=2) {
			int w = t;
			long sum = 0;
			for(int j=i;j<=n&&t!=0;j++,t--) {
				sum+=res[j];
			}
			if(sum>MAX) {
				MAX = sum;
				key = cs;
			}
			t = w;
		}
		System.out.println(key);
	}
}
相关推荐
Nil2087 小时前
leetcode 17电话号码的字母组合
算法·leetcode·职场和发展
artificiali12 小时前
拼好卷 05
职场和发展
AIsoft_868815 小时前
最好用的会议纪要APP怎么选?功能横评
面试·职场和发展·iphone
aqiu11111115 小时前
【并查集 / 图论】蓝桥云课 - 魔法大陆的城市群(求无向图连通块数量)题解
蓝桥杯·图论
Nil20817 小时前
leetcode 46全排列
算法·leetcode·职场和发展
测试199818 小时前
Jmeter接口自动化生成测试报告html格式详解
自动化测试·python·测试工具·jmeter·职场和发展·测试用例·接口测试
2401_8322981018 小时前
AI重塑职场生态:人机协同开启全新工作范式
职场和发展
火眼金睛炼单词19 小时前
背单词攻略文章
职场和发展
aqiu1111111 天前
【LeetCode 902】最大为 N 的数字组合 - 详细题解与数位组合思路
数据结构·算法·leetcode·蓝桥杯·数位dp