Basics of Lanqiao Cup - [Slicing Noodles] Problem-solving ideas without drawing

Insert image description here

Let’s look at the topic of [Slicing Noodles] first:

一根高筋拉面,中间切一刀,可以得到2根面条。
如果先对折1次,中间切一刀,可以得到3根面条。
如果连续对折2次,中间切一刀,可以得到5根面条。 
那么,连续对折10次,中间切一刀,会得到多少根面条呢?

Problem-solving ideas:

When we get an algorithm question, we first perform a mathematical analysis on it. Since it is an algorithm question, it must be within the category of mathematics, and things within the category of mathematics have rules to follow. And you just need to review the questions carefully and let the patterns appear in front of you.

The question asked is [if you fold it in half 10 times and cut it in the middle, how many noodles will you get? ], and began to conduct mathematical analysis: what we are looking for is the relationship between the number of folds and the number of noodles, because the number of cutters is a constant, which is always 1. Then queue:

  1. Fold it in half once to get 3 noodles;
  2. Fold it in half twice to get 5 noodles;
  3. Fold it in half 10 times to get a noodle;

The rule is found. Every time you fold n times, the number of noodles obtained is 2n+1, so fold it in half 10 times and the result is 2x10+1=21.

You happily used the solved problems to please the teacher, and then the teacher DBD caused deep harm to your young heart, butYou are very strong< /span> . Basics of Blue Bridge Cup - [Slicing Noodles], no need to draw pictures . At this time, you go over the question carefully again, but you still don’t know why. In the end, you went to Baidu to search for this blog post

Correct problem-solving ideas:

When you see this kind of question, you must examine it carefully and don't be fooled by the appearance. What you are looking for is the result after folding in half 10 times; but folding in half 0 times is also folding in half, and it is within the rules. So requeue:

  1. Fold in half 0 times to get 2 noodles;
  2. Fold it in half once to get 3 noodles;
  3. Fold it in half twice to get 5 noodles;
  4. Fold it in half 10 times to get a noodle;

At this time, you find that the rule you found earlier does not apply, because when folded 0 times, the value obtained by 2n+1 is 1, which is the same as The results of the question [Fold in half 0 times and cut once in the middle to get 2 noodles] are not equal. At this moment, you suddenly realize, slap your forehead, and shout: mlgbzd, it turns out that the rule is 幂次方.

When three results are determined, a pattern is basically found.

  1. Fold in half 0 times to get 2º+1=2;
  2. Fold it in half once to get 2¹+1=3;
  3. Fold it in half twice to get 2²+1=5;
  4. Fold it in half 10 times to get 2¹º+1 = 1025;
// n为对折次数
function getNoodlesSplit(n){
    
    
	return 2**n + 1;
}
let result = getNoodlesSplit(10);
console.log(result); // 1025

Guess you like

Origin blog.csdn.net/ThisEqualThis/article/details/129569686