[Daily Lanqiao] 20, 2014 provincial competition Java group real question "Cut noodles"

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: Cut Noodles

One high-gluten ramen, cut a knife in the middle, you can get 2 noodles

If you fold it in half and cut it in the middle, you can get 3 noodles

If you fold in half twice in a row and cut in the middle, you can get 5 slim pieces

So, how many noodles will you get if you fold it in half 10 times and cut it in the middle?

The answer is an integer, please submit the answer through the browser, do not fill in any extra content

Problem-solving ideas:

This question is a fill-in-the-blank question, we can deduce the number of pieces that can be cut according to the meaning of the question

Number of folds Number of items
    0 2
    1 3
    2 5
    3 9
    4 17
    ...
    n 1+2 to the power of n

From this, the above rules can be derived,

Then when folded 10 times, the number of pieces obtained is 1-2 to the 10th power = 1025 pieces

Answer source code:

public class Year2014_Bt2 {

	public static void main(String[] args) {
		int n=10;
		double ans = 1 + Math.pow(2, n);
		System.out.println(ans);
	}
}

 

 

Sample output:

 

There are deficiencies or improvements, and I hope that my friends will leave a message and 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/113511309