蓝桥杯(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);
	}
}
相关推荐
我命由我123456 小时前
Photoshop - Photoshop 快速共享作品
学习·ui·职场和发展·求职招聘·职场发展·学习方法·photoshop
我命由我123456 小时前
自动化 / 智能装配的对象、内容、层级
运维·学习·职场和发展·自动化·求职招聘·职场发展·学习方法
AI职业加油站6 小时前
大模型开发工程师证书怎么考?零基础学习路径与价值拆解
大数据·人工智能·学习·职场和发展·数据分析
blxr_7 小时前
力扣hot100爬楼梯https://leetcode.cn/problems/climbing-stairs/
算法·leetcode·职场和发展
我命由我123459 小时前
Photoshop - 将Photoshop图像置入其他应用程序
学习·ui·职场和发展·求职招聘·职场发展·学习方法·photoshop
blxr_11 小时前
力扣hot100前k个高频元素https://leetcode.cn/problems/top-k-frequent-elements/
算法·leetcode·职场和发展
财情双生教练易和中1 天前
“找矿大会战”产业链,量化统计研究报告
职场和发展·职业发展·创业创新·程序员创富
yuanxi2001 天前
001267拟扩产光模块:大客户销售如何用价值力读一条扩产公告
人工智能·职场和发展·创业创新·学习方法
Interview Aid1121 天前
Google SWE Intern Interview Process:OA、Coding 与面试流程详解
面试·职场和发展
垆边人似月.1 天前
字符串重排后最大字典序
算法·leetcode·职场和发展