蓝桥杯(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);
	}
}
相关推荐
是翎1 小时前
AI开发工程师面试指南
人工智能·面试·职场和发展
Interview Aid1123 小时前
Amazon SDE Interview Process:OA、VO 与面试流程详解
面试·职场和发展
Nil2087 小时前
leetcode 739每日温度
算法·leetcode·职场和发展
yuanxi2009 小时前
中国汽车企业欧洲网点扩张:大客户销售的关系力启示
职场和发展·汽车·创业创新·学习方法
Dream it possible!12 小时前
LeetCode_热题100_知识点总结
算法·leetcode·职场和发展
杨逢昌工厂6S管理14 小时前
107-杨逢昌钣金车间换型管控:从物料切换杂乱到有序换型的四步技术方案
经验分享·笔记·职场和发展·学习方法
ychqsq1 天前
203.诊断
经验分享·职场和发展
ychqsq2 天前
201.春风
经验分享·职场和发展
泡沫_花火2 天前
大模型开发相关岗位面试资料(含算法)
语言模型·自然语言处理·面试·职场和发展
我命由我123452 天前
Photoshop - Photoshop 快速共享作品
学习·ui·职场和发展·求职招聘·职场发展·学习方法·photoshop