题目描述
思路分析
等差数列
代码实现
package lanqiao;import java.util.*;
public class Main {public static void main(final String[] args) {Scanner sc = new Scanner(System.in);int n=sc.nextInt();int[]nums=new int[n+1];long maxSum=0;int minDeep=Integer.MAX_VALUE;for(int i=1;i<=n;i++)nums[i]=sc.nextInt();int deep=0;for(int i=1;i<=n;i=i+(int)Math.pow(2, deep-1)) {long sum=0;//最后一层可能不满,一定要加上j<=n,否则数组越界for(int j=i;j<i+(int)Math.pow(2, deep)&&j<=n;j++) {sum+=nums[j];}if(sum>maxSum) {minDeep=deep+1;maxSum=sum;}deep++;}System.out.println(minDeep);}
}