[Daily Blue Bridge] 45.17 Provincial Competition Java Group Real Question "Pressure Calculation"

Hello, I am the little gray ape, a programmer who can write bugs!

Welcome everyone to pay attention to my column " Daily Blue Bridge ". The main function of this column is to share with you the real questions of the Blue Bridge Cup provincial competitions and finals in recent years, analyze the algorithm ideas, data structures and other content that exist in it, and help you learn To more knowledge and technology!

Title: Pressure Calculation

A certain batch of precious metal materials are neatly stacked in the high-tech laboratory of Planet X.

The shape and size of each piece of metal material are exactly the same, but the weight is different.

The metal materials are strictly stacked in a pyramid shape.

The number represents the weight of the metal block (the unit of measurement is larger).

The X on the bottom layer represents 30 extremely high-precision electronic scales.

Assuming that the weight of each piece of raw material falls very accurately on the two metal pieces below,

Finally, the weight of all the metal blocks is strictly and accurately divided equally on the bottom electronic scale.

The unit of measurement of the electronic scale is very small, so the displayed number is very large.

The staff found that the reading of the electronic scale with the smallest reading was: 2086458231

Please calculate: What is the indication of the electronic scale with the largest reading?

Note: What needs to be submitted is-an integer, do not fill in any extra content.

Problem-solving ideas:

This question is mainly to understand the meaning of the question, transform the pyramid into a two-dimensional array for processing, and each row needs to be divided equally.

Answer source code:

import java.util.Arrays;
import java.util.Scanner;

public class Year2017_Bt3 {

	static long [][] arr = new long[30][30];
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		long factor = 1;
		for (int i = 0; i < 30; i++) {
			factor<<=1;
		}
		
//		输入数据放入二维数组
		for (int i = 0; i < 29; i++) {
			for (int j = 0; j <= i; j++) {
				long a = scanner.nextLong();
				arr[i][j]=a*factor;
			}	
		}
		
//		循环处理1~N-1行
		for (int i = 0; i < 29; i++) {
			for (int j = 0; j <= i; j++) {
				long ha = arr[i][j]/2;
				arr[i+1][j]+=ha;
				arr[i+1][j+1]+=ha;
			}	
		}
		
		Arrays.sort(arr[29]);
		System.out.println(arr[29][0]);
		System.out.println(arr[29][29]);
		System.out.println(arr[29][29]/(arr[29][0]/2086458231));
	}

}

Sample output:

 

There is insufficient or those areas of improvement, but also hope that the message put forward a small partner, learn together!

Interested friends can follow the column!

Little Gray Ape will accompany you to make progress together!

 

Guess you like

Origin blog.csdn.net/weixin_44985880/article/details/115270220