Branch branch tree rebus solution. Review questions

Let's call this method - controlled enumeration.

program task3_8c;

for k:=1 to 4 do

for t:=2 to 9 do

if k<>t then

for o:=0 to 9 do

if (k<>o) and (t<>o) then

kto:=k*100+t*10+o;

kot:=k*100+o*10+t;

current:=t*100+o*10+k;

if kto+kot=tok then writeln(kto,"+",kot,"=",tok);

Such an algorithm, even with 8-10 nested loops, works very quickly.

Review questions:

1. Can nested loops use the same variable, such as i?

2. Is it possible to nest different loops: FOR in WHILE or REPEAT in FOR?

Tasks for independent work:

1. Old task. How many bulls, cows and calves can be bought if a bull costs 10 rubles, a cow costs 5 rubles, a calf costs fifty dollars (0.5 rubles), provided that 100 heads of cattle must be bought for 100 rubles.

2. Given a natural number n. For all numbers from 1 to n find:

a) number of divisors; b) the sum of even divisors.

3. Find all solutions of the following numerical puzzles:

a) GRANNY + GRANDFATHER + TURP = TALE (4 solutions)

b) COW + GRASS + MILKWORKER = MILK (2 solutions)

c) ALYONKA + IVAN + GOAT = TALE (1 solution)

d) BRANCH + BRANCH + STEM = TREE (3 solutions)

e) GATE + GRASS = FOOTBALL (3 solutions)

Learning "Cycles"

M4_Block #3

Lesson topic :

nested loops.

Purpose of the lesson:

1. To consolidate knowledge on the use of various types of cycles;


2. Get skills in solving algorithms with nested loops.

Secondary School No. 1, Lida

To solve a problem, it is often necessary to use several nested cyclic structures. Such constructions are called nested loops.

Let's look at a few examples:

Given a natural numberS. It is required to write a program to find all rectangles whose area is equal toSand the sides are expressed in natural numbers.

program task3_6;

var s, a, b:longint;

writeln("Enter s"); readln(s);

for a:=1 to s do

for b:=1 to s do

if a*b=s then writeln ("sides ",a," and ",b);

This problem could be solved using only one cycle. Think about how to do it.

Given natural numbersn, m. Get all natural numbers less thann, the sum of the squares of whose digits is equal tom.

program task3_7;

var n, m, i, a, sum, cif:longint;

writeln("enter n and m"); readln(n, m);

for i:=1 to n do

sum:=sum+sqr(cif);

if sum=m then write(i," ");

Find all solutions of a given numerical puzzle. Each letter corresponds to a number. Moreover, the same letters correspond to the same numbers, different letters - different numbers.

Since there are only three letters here, it is enough to write three nested loops for the solution, and go through all the options for adding three-digit numbers.

program task3_8a;

vark, t, o, kto, kot, tok:longint;

for k:=0 to 9 do

for t:=0 to 9 do

for o:=0 to 9 do

kto:=k*100+t*10+o;

kot:=k*100+o*10+t;

current:=t*100+o*10+k;

if (k<>t) and (k<>o) and (t<>o) and (kto+kot=tok) then

writeln(kto,"+",kot,"=",tok);

In this algorithm, the cycle body was executed 10∙10∙10=1000 times. (will talk algorithm complexity =1000)

If, however, to solve more complex puzzles, you need to write 8-10 nested loops, then such a complete enumeration will work for a long time.

You can simplify this algorithm a bit if you see that 1≤k≤4, t≥2.

for k:=1 to 4 do

for t:=2 to 9 do

for o:=0 to 9 do

Now the complexity of the algorithm is 4∙8∙10=320. A simple cosmetic fix resulted in a 3x speed increase.

But this algorithm is not optimal either. Look at k=2 and t=2 the program will go through all 10 options o. In such cases when k=t cycle by o should not be done at all.

Who among us is not familiar with puzzles? These entertaining ciphers are familiar to everyone from young to old. In puzzles, words are encrypted using a sequence of pictures and different symbols, including letters and numbers. The word "rebus" is translated from Latin as "with the help of things." The rebus originated in France in the 15th century, and the first printed collection of puzzles published in this country in 1582 was compiled by Etienne Taburo. In the time that has passed since then, the technique of compiling rebus problems has been enriched with a variety of different techniques. To solve the rebus, it is important not only to know what is drawn, but also to take into account the location of the drawings and symbols relative to each other, and this is achieved by practice. There are some unspoken rules by which puzzles are made up, and it is easier to solve them also according to the same rules, and the rules are as follows:

General rules for solving puzzles

The word or sentence in the rebus is divided into parts, which are depicted in the form of a picture or symbol. The rebus is always read from left to right, less often from top to bottom. Spaces and punctuation marks are not read. What is drawn in the pictures in the rebus is read in the nominative case, usually in the singular, but there are exceptions. If several objects are drawn, the arrow indicates which part of the entire image is used in this rebus. If not one word is guessed, but a sentence (proverb, catchphrase, riddle), then in addition to nouns there are verbs and other parts of speech. Usually this is specified in the task (for example: “Guess the riddle”). The rebus must always have a solution, and one. The ambiguity of the answer should be specified in the conditions of the rebus. For example: “Find two solutions to this puzzle.” The number of techniques used in one rebus and their combinations is not limited.

How to solve puzzles from pictures

They name all objects sequentially from left to right in the nominative singular.

Answer: track experience = tracker

Answer: ox box = fiber

Answer: eye of the face = outskirts

If the object is drawn upside down, its name should be read from right to left. For example, a “cat” is drawn, you need to read “current”, a “nose” is drawn, you need to read “dream”. Sometimes reading directions are shown with an arrow.

Answer: dream

Often an object drawn in a rebus can be called differently, for example, “meadow” and “field”, “leg” and “paw”, “tree” and “oak” or “birch”, “note” and “mi”, in such cases, you need to select a suitable word, such that the rebus has a solution. This is one of the most important difficulties in solving puzzles.

Answer: oak rava \u003d oak grove

How to solve puzzles with commas

Sometimes the name of the item depicted cannot be used in its entirety and one or more letters at the beginning or end of the word must be dropped. Then a comma is used. If a comma is to the left of the figure, the first letter is discarded from its name, if it is to the right, the last. How many commas are worth, so many letters are discarded.

Answer: ho ball k = hamster

For example, 3 commas and a “feeder” are drawn, you only need to read the “fly”; “sail” and 2 commas are drawn, you only need to read “steam”.

Answer: Umbrella p = pattern

Answer: li sa to por gi = boots

How to solve puzzles with letters

Such letter combinations as before, above, on, under, behind, at, y, in, as a rule, are not depicted in puzzles, but are identified from the corresponding position of letters and drawings. Letters and letter combinations from, to, from, from, to, and are not shown, but the relationship of letters or objects, or direction.

If two objects or two letters, or letters and numbers are drawn one into the other, then their names are read with the addition of the preposition "in". For example: “v-o-yes”, or “v-o-seven”, or “no-v-a”. A different reading is possible, for example, instead of "eight" you can read "seven-in-o", and instead of "water" - "yes-in-o". But such words do not exist, therefore such words are not a solution to the rebus.

Answers: v-o-yes, v-o-seven, v-o-lx, v-o-ro-n, v-o-mouth-a

If one object or symbol is drawn under another, then we decipher it with the addition of “on”, “above” or “under”, you need to choose a preposition according to the meaning. Example: “fo-na-ri”, “under-at-shka”, “above-e-wa”.

Answers: for-on-ri, under-at-shka, over-e-wa

If behind any letter or object there is another letter or object, then you need to read with the addition of “for”. For example: “Ka-za-n”, “za-ya-ts”.

Answer: for-i-c

If one letter lies next to another or is leaning against it, then they read with the addition of "y" or "k". For example: “L-u-k”, “d-u-b”, “o-k-o”.

Answers: onion, oak

If a letter or syllable consists of another letter or syllable, then read with the addition of "from". For example: “from-b-a”, “b-from-he”, “out-of-y”, “f-from-ik”.

Answers: hut, bison

If another letter or syllable is written throughout the letter, they read with the addition of “by”. For example: “po-r-t”, “po-l-e”, “po-i-s”. Also, "by" can be used when one letter with legs runs over another letter, number or object.

Answer: Poland

Answers: belt, field

If an object is drawn, and a letter is written next to it, and then a letter is crossed out, this means that this letter must be thrown out of the word. If there is another one above the crossed out letter, then this means that it is necessary to replace the crossed out one with it. Sometimes in this case an equal sign is placed between the letters.

Answer: laz

Answer: raspberry z Mont \u003d lemon

How to solve puzzles with numbers

If there are numbers above the picture, this is a hint in what order to read the letters from the name of the subject. For example, 4, 2, 3, 1 means that the fourth letter of the name is read first, then the second, followed by the third and first.

Answer: brig

The numbers can be crossed out, which means you need to discard the letter corresponding to this order from the word.

Answer: horse ak LUa bo mba = Columbus

Quite rarely, the action of the letter is used in rebuses - it runs, flies, lies, in such cases, the corresponding verb in the third person of the present tense must be added to the name of this letter, for example, “y-runs”.

How to solve puzzles with notes

Often in rebuses, individual syllables corresponding to the names of notes - “do”, “re”, “mi”, “fa” ... are depicted with the corresponding notes. Sometimes the generic word "note" is used.

Notes used in composing puzzles


Answers: beans, minus

Having familiarized yourself with the rules of how to solve puzzles, you can easily not only solve any puzzle, but also learn how to make a puzzle yourself.

  1. The name of everything that is shown in the pictures in the rebus is read only in the nominative case.
  2. The picture in the rebus can have more than one name. Example: leg and paw, eye and eye; or the image may have a general or private name (a bird is a common name; a rooster, a dove, a seagull is a private name).
  3. Commas (whether inverted or not) indicate that extreme letters should be removed from the word. Words first if the commas are before the picture, or from the end of the word if the commas are after the picture. The number of letters to be removed corresponds to the number of commas. FOREST
  4. Strikethrough letters - such letters should be removed from the word. If the crossed out letters are repeated, then they are all removed. CASH REGISTER
  5. Strikethrough numbers indicate that in the word such a letter should be removed.
  6. The equal sign between letters (A=E) indicates that you need to replace all the letters A with E. Equality 1=E indicates the replacement of only the first letter in the word. STRENGTH
  7. The arrow between the letters (E -> B) also indicates the corresponding replacement of letters.
  8. The numbers 1,2,7,5 above the picture indicate that you need to take the letters 1,2,7,5 from the given word and compose them in the order in which the numbers are located. TANK
  9. The picture turned upside down indicates that the word should be read from right to left. (CAT - CURRENT)
  10. The arrow pointing to the left above the picture indicates that after the word is deciphered, it must be read backwards. CAT
  11. When a fraction is used in a rebus, it is solved as "ON" (divide ON). If a fraction with a denominator 2 is used in the rebus, then this is solved as "FLOOR" (half). SHELF FLASHLIGHT
  12. When compiling puzzles, notes are used. To determine the note, only the line on which the note is located matters. black dot(note).
  13. Inside the letter "O" is the syllable "YES", it turns out V-O-YES, i.e. "WATER". It can also be read as "YES-V-O". The option that makes the most sense is selected. WILL
  14. When the pictures are located one above the other, it is read as "OVER", "ON", "UNDER" (depending on what fits in the meaning). GIFT A PINEAPPLE
  15. A letter consisting of other letters is read as a preposition "FROM". For example, from the letter "B" we make the letter "A", then we get: from "B" "A" (IZBA). hut
  16. A letter located on top of another letter is read as "PO". FIELD
  17. The letter depicted behind another letter is read as a preposition "FOR" or "BEFORE". The option that makes the most sense is selected. HARE
  18. The sign "+" means the preposition "K" (Note 2 + 3 can be read: To add Three to Two or Three to add To Two). You should choose the option that makes sense. Window cocoon
  19. A double arrow between the numbers means that the letters under these numbers need to be swapped with each other. foot
  20. The crossed-out sign "=" between the pictures should be read as "NOT" (Example: "C" is NOT equal to "G"). Snow

Well, now you are ready to solve any puzzle?

P.S.: If you know any other rules for solving puzzles or notice some inaccuracy in the description of the existing rules, then please write about it in the comments below.

(jcomments on)