Primary school games and procedures

xiaoxiao2021-04-08  399

Primary school game

Program file name: Pupil.cpp / pupil.pas / ...

One day, boring Xiaojie called several students playing games, including stupid small phoenix, more silly snow, cute Xiaoxin and self-righteous skills. They go to find a smart craft to give them a referee. Decide whoever gets the game victory. And this game is: given a number A by the small art, give a number B, after the specified operation, make the number A converted to the number B, and the minimum change number n. Who said to this n, who Get the victory. Of course, because it is a primary school, it is assumed that if n> 6 is, even if there is no answer. Then the referee craft tries to obtain the answer as soon as possible. Please help him ...

Problem Description:

The title gives a number A (A is a positive integer, no more than 50), give the number B (same as a positive integer, no more than 50),

There are three calculations of the number:

1: Make the current number of 1985429

2: Make the current number with 2006

3: Make the current number 2

Need you to find this minimum N, if n> 6, output -1. (This is negative).

Example 1: The small art gives a number A = 1, given the number b = 1987437

So fastest, we can make 1 turn to 1987437 after 3 specified calculations

1 * 2 = 2; (third transformation)

2 1985429 = 1985431; (1st transformation)

1985431 2006 = 1987437; (2nd transformation)

Example 2: The small art gives a number A = 1, given the number b = 128

So fastest, we can make 1 turn to 128 after 7 specified operations

1 * 2 * 2 * 2 * 2 * 2 * 2 * 2 = 128 (all of the third transformation), but because n> 6, it is displayed in accordance with the meaning of the title.

Enter (please use standard input and output, not to read and write)

Enter only two integers A, B, one digits per row, 0 <1 <1e 50, 0

Output (please use standard input and output, not to read and write)

The output is only one line, that is, the minimum number of transformations n, if n> 6 outputs -1.

Sample input

1

Sample output

1

1

1987437

3

Sample input

2

Sample output

2

1

128

-1

#include #include #include #include

Void main () {Int Innum, Outnum; INT Total; INT J = 0; INT K = 0; INT i = 0; BOOL FLAG = FALSE; CIN >> Innum >> OUTNUM;

Total = Innum; for (i = 0; i <5; i ) // 1 198429, then 2006, last * 2. {INT TEMP1 = Total; for (j = 0; j <900; j ) {int TEMP2 = TEMP1; for (k = 0; k <1000000; k ) {if (TEMP2 == OUTNUM) {Flag = true; cout << "============ 1 ========================" << Endl; goto loop;} if (temp2> outnum) Break; temp2 * = 2;} if (temp1 == outnum) {flag = true; cout << "============ 1 ===============" < OUTNUM) BREAK; TEMP1 = 2006;} if (total == OUTNUM) {FLAG = true; cout << "============ 1 = =============== "<< Endl; goto loop;} if (total> outnum) Break; Total = 1985429;} 1 / total = Innum; for (i = 0; i < 900; i ) // 2006, then 198429, last * 2.

{INT TEMP1 = Total; For (j = 0; j <5; j ) {int TEMP2 = TEMP1; for (k = 0; k <1000000; k ) {if (TEMP2 == OUTNUM) {Flag = true; cout << "============= 2 ========================" << Endl; goto loop;} if (temp2> outnum) Break; temp2 * = 2;} if (temp1 == outnum) {flag = true; cout << ============ 2 =============== "< OUTNUM) BREAK; TEMP1 = 1985429;}} (total == OUTNUM) {Flag = true; cout << "============ 2 = =============== "<< Endl; goto loop;} if (total> Outnum) Break; Total = 2006;} 2 /// Total = Innum; for (i = 0; i <900; i ) // 2006 first 2006, then * 2, last 198429.

{INT TEMP1 = Total; For (j = 0; j <1000000; j ) {int TEMP2 = TEMP1; for (k = 0; k <5; k ) {= == Outnum) {Flag = true; cout << ============ 3 =============== "<< Endl; goto loop;} if (temp2> outnum) Break; temp2 = 1985429;} if (temp1 == outnum) {flag = true; cout << "============ 3 ===============" << Endl; goto loop;} if (temp1> OUTNUM) BREAK; TEMP1 * = 2;} if (total == OUTNUM) {Flag = true; cout << ===================================== 3 = ============== "<< Endl; goto loop;} f (total> outnum) Break; Total = 2006;} / 3 /// Total = Innum; for (i = 0 i <5; i ) // 1 198429, then * 2, last 2006.

{INT TEMP1 = Total; for (j = 0; j <100000; j ) {int TEMP2 = TEMP1; for (k = 0; k <900; k ) {if (TEMP2 == OUTNUM) {Flag = true; cout << ============================= "<< Endl; goto loop;} if (Temp2> OUTNUM) BREAK; TEMP2 = 2006;} if (temp1 == outnum) {flag = true; cout << ============ 4 =============== "<< Endl; goto loop;} if (temp1> outnum) Break; Temp1 * = 2;} if (total == OUTNUM) {Flag = true; cout << ============================================================================================================================================================================== ============== "<< Endl; goto loop;} f (total> Outnum) Break; Total = 1985429;} // 4 // Total = Innum; for (i = 0 ; i <1000; i ) // First * 2, then 198429, last 2006.

{INT TEMP1 = Total; for (j = 0; j <5; j ) {int TEMP2 = TEMP1; for (k = 0; k <900; k ) {if (TEMP2 == OUTNUM) {Flag = true; cout << "======================= 1 =====" << Endl; goto loop;} if (Temp2> OUTNUM) BREAK; TEMP2 = 2006;} if (temp1 == Outnum) {flag = true; cout << ======================= 2 ====== " << Endl; goto loop;} if (temp1> outnum) Break; temp1 = 1985429; // a} if (total == OUTNUM) {flag = true; cout << "========== == 5 ========= 3 ====== "<< Endl; goto loop;} if (total> Outnum) Break; Total * = 2; // C} // 5 / Total = Innum; for (i = 0; i <100000; i ) // 1 * 2, then 198429, last 2006.

转载请注明原文地址:https://www.9cbs.com/read-132746.html

New Post(0)