Using C + + to solve the maths problem of Vietnamese primary school

Source: Internet
Author: User

It is learnt that the topic comes from the three-year class of Paul's primary school in Viet Nam, students need to fill in 1 to 9 numbers from top to bottom, from left to right, and to complete the whole calculation by adding and reducing the algorithm according to the first multiplication.

650) this.width=650; "title=" original. jpg "alt=" wkiom1vqlgcgeoiqaabghlcz6ky705.jpg "src=" http://s3.51cto.com/wyfs02/M00/ 6d/bc/wkiom1vqlgcgeoiqaabghlcz6ky705.jpg "/>


Chen Fang, deputy director of the Hanoi Family Breeding center, said that the topic needed only basic arithmetic skills, and he invited some adults to challenge them, including those with a PhD in economics, but none of them could answer.


People are hard to do things, with a computer to solve is much easier. We use the C + + programming language to calculate this problem using the brute-lifting method. The basic idea of the exhaustive method is to determine the approximate scope of the answer based on some of the conditions of the topic, and to validate all possible cases within this range until all the circumstances have been verified. If a situation verifies that all the conditions of the subject are met, then it is a solution to the problem and if all the conditions are not met, then there is no solution. The exhaustive method is also known as the enumeration method.


In the empty box listed in the original question, fill in the unknowns of A, B, C, D, E, F, G, H, I, as shown:

650) this.width=650; "Title=" set the unknown after the figure. jpg "alt=" wkiom1vqlh-ckdihaaczdslr6u8297.jpg "src=" http://s3.51cto.com/ Wyfs02/m02/6d/bc/wkiom1vqlh-ckdihaaczdslr6u8297.jpg "/>

Depending on the column you can get: a+13*b/c+d+12*e-f-11+g*h/i-10 = 66

To further simplify the formula: a+13*b/c+d+12*e-f+g*h/i = 87

The values of a, B, C, D, E, F, G, h, and I are known to be [1,9], so the exhaustive calculation has a 9*9*9*9*9*9*9*9*9=9^9=387420489, and we want to sift through the total number of decisions to match the result of the equation. The number of unknowns can be determined by a cycle of 9 layers. Each layer increments from 1 to 9 with a step of 1. So we can easily write the source code.


Console programs in the Windows 7 64-bit Simplified Chinese Professional Edition and C + + Builder 2010 Integrated Development Environment Source code:

---------------------------------------------------------------------------#pragma  hdrstop#include  <tchar.h> #include  <iostream>using namespace std;//--------------------------- ------------------------------------------------#pragma  argsusedint _tmain (int argc, _ Tchar* argv[]) {float a, b, c, d, e, f, g, h, i;  / /Set 9 unknowns int counter = 0;       //counter Const int my_ Max = 10;  //1-9 in the range of numbers for (a = 1.0; a < my_max; a=a+1) for ( b = 1.0; b < my_max; b=b+1) for (c = 1.0; c < my_ max; c=c+1) for (d = 1.0; d < my_max; d=d+1) for (e = 1.0; e  < my_max; e=e+1) for (f = 1.0; f < my_max; f=f+1) for (g  = 1.0; g  < my_max; g=g+1) for (h = 1.0; h < my_max; h=h+1) for (i =  1.0; i < my_max; i=i+1) {// a+13*b/c+d+12*e-f-11+g*h/i-10 == 66.0if   (a+13*b/c+d+12*e-f+g*h/i == 87.0)    //calculates the value of the equation and determines whether it is a set of solutions {      cout <<  "["  << ++counter <<  "]\t"; cout < <  "a="  << a <<  "; "; cout <<  "b="  < < b <<  "; "; cout <<  "c="  << c <<   "; "; cout <<  "d="  << d <<  "; ";  cout <<  "e="  << e <<  "; "; cout <<  " f= " << f << ";  "; cout << " g= " << g  <<  ";  "; cout << " h= " << h << ";  "; cout  <<  "i="  << i <<  "; \ n";}} System ("PAUSE"); return 0;} //---------------------------------------------------------------------------

650) this.width=650; "title=" capture. JPG "alt=" wkiol1vqukdyb8wsaabah-zhyda789.jpg "src=" http://s3.51cto.com/wyfs02/M00/6D/B9/ Wkiol1vqukdyb8wsaabah-zhyda789.jpg "/>


The program runs some of the results such as:

650) this.width=650; "Title=" The last group of solutions to the small figure. JPG "alt=" wkiol1vqlvbcing1aapfhe85dme080.jpg "src=" http://s3.51cto.com/wyfs02/M00/6D/B7/ Wkiol1vqlvbcing1aapfhe85dme080.jpg "/>


Using C + + to solve the maths problem of Vietnamese primary school

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.