③【Java Group】The real questions of the Blue Bridge Cup Provincial Competition [Golden Continuing Fractions] [Sloppy Calculations] are being updated continuously...

insert image description here

Personal brief introduction: New star creator in the Java field; Alibaba cloud technology blogger, star blogger, expert blogger; on the way of learning Java, recording the learning process~ Personal homepage: .29.'s blog
Learning community
: Go in and have a stroll~

insert image description here





1. Golden consecutive fractions (fill in the blank)


题目描述

insert image description here

Text version:
The golden section number 0.61803... is an irrational number. This constant is very important and will appear in many engineering problems. Sometimes it is necessary to obtain this figure very precisely.

For some precision engineering, the precision of the constants is important. You may have heard of the Hubble Space Telescope, which discovered a human error after its first lift-off. For such a huge object, it was actually just an error in the processing of the mirror many times thinner than a human hair. It became "nearsighted"!!

Closer to home, how do we find the most accurate value of the golden section number? There are many ways.

A simpler one is to use continued fractions:

                  1
    黄金数 = ---------------------
                        1
             1 + -----------------
                          1
                 1 + -------------
                            1
                     1 + ---------
                          1 + ...

The more "layers" this continued fraction calculates, the closer its value is to the golden section number.

Please use this feature to find a sufficiently accurate value of the golden section number, which requires rounding to 100 decimal places.

The value of 3 digits after the decimal point is: 0.618;

The value of 4 digits after the decimal point is: 0.6180;

The value of 5 digits after the decimal point is: 0.61803;

The value of 7 decimal places is: 0.6180340. (Note the trailing 00, which cannot be ignored)

Your task is: write the golden section value accurate to 100 decimal places.

Note: rounding of the mantissa! If the mantissa is 0, it should also be reserved


解题思路:
According to the schematic diagram of the continued fraction of the golden number given in the title, we can find that the numbers between adjacent levels are related:
① Denominator of the golden number = denominator of the previous level + numerator
② The numerator of the golden number = the previous level Count the denominator
and the change of the numerator and the denominator happens to be the Fibonacci sequence, then we convert the problem into finding the ratio of two adjacent Fibonacci numbers.
At the same time, the title requires writing the golden section value accurate to 100 digits after the decimal point. Floating point numbers can no longer satisfy so many decimal places, so BigInteger and BigDecimal need to be used.


解题代码:

import java.math.BigDecimal;
import java.math.BigInteger;

//求斐波那契额相邻两个数的比值,需要保证小数点后101位准确,使用BigInteger和BigDecimal
public class 黄金连分数 {
    
    
	public static void main(String[] args) {
    
    
		BigInteger a = BigInteger.ONE; //a代表分子
		BigInteger b = BigInteger.ONE; //b代表分母
		
		for(int i = 3;i < 500;i++) {
    
     //第一层是 1/1 (已知),所以从第三个数开始
			BigInteger temp = b;
			b = a.add(b);       //黄金数的分母 = 上一层数 分母+分子
			a = temp;           //黄金数的分子 = 上一层数分母
		}
		
		//创建BigDecimal对象,小数点没有限制;
		//divide()方法表示除法运算
		BigDecimal divide = new BigDecimal(a,110).divide(new BigDecimal(b,110),BigDecimal.ROUND_HALF_DOWN);
		
		//输出黄金分割数,精确到101位(103代表字符数,包含0和.)
		System.out.println(divide.toPlainString().substring(0,103));
		//0.61803398874989484820458683436563811772030917980576286213544862270526046281890244970720720418939113748
		//小数点后101位,我们需要四舍五入至100位
		//0.6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911375
	}

}

答案:0.6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911375




2. Sloppy calculation (fill in the blank)


题目描述

insert image description here

Text version:
Xiao Ming is impatient. When he was in elementary school, he often copied the wrong questions written by the teacher on the blackboard.

Once, the teacher asked the question: 36 x 495=?

But he copied it: 396 x 45=?

But the result was dramatic, and his answer turned out to be right! !

Because 36*495=396*45=17820.

There may be many coincidences like this, for example: 27∗594=297∗54.

Suppose abcde represents 5 different numbers from 1 to 9 (note that they are different numbers and do not contain 0)

How many formulas can satisfy the formula: ab∗cde = adb∗ce?

Please use the advantages of the computer to find all the possibilities and answer the number of types of different calculation formulas.

The calculation formulas that satisfy the commutative law of multiplication are counted as different types, so the answer must be an even number.


解题思路

According to the requirements of the topic, traverse all the number combinations, and when you find a formula that meets the conditions, just add 1 to the number of types.


解题代码:

public class 马虎的算式 {
    
    
	public static void main(String[] args){
    
    
		int count = 0;  //记录种类数
		//数字1~9随机,故遍历所有循环,abcde间的所有数字可能,则需要不断嵌套循环
		for(int a = 1;a < 10;++a) {
    
    
			for(int b = 1;b < 10;++b) {
    
    
				//循环前进行判断,保证是各不相同的数字
				if(a != b) for(int c = 1;c < 10;++c) {
    
    
					if(a != c && b!= c) for(int d = 1;d < 10;++d) {
    
    
						if(a != d && b != d && c != d) for(int e = 1;e < 10;++e) {
    
    
							if(a != e && b != e && c != e && d != e)
								//如果 ab∗cde = adb∗ce
							if((a*10 + b ) * (c*100+d*10+e) == (c*10 + e ) * (a*100+d*10+b))
								//数量+1
								++count;
						}
					}
				}
			}
		}
		System.out.print(count);
	}
}





insert image description here

Guess you like

Origin blog.csdn.net/ebb29bbe/article/details/129272467