make up the formula

Computational formula

       B DEF
A + — + -—— = 10
       C GHI

(If there is a problem with the display, please refer to [Figure 1.jpg])

In this formula, A~I represent numbers from 1 to 9, and different letters represent different number.

For example:
6+8/3+952/714 is one solution,
5+3/1+972/486 is another solution.

How many solutions are there to this equation?

Note: Your submission should be an integer, do not fill in any extra content or descriptive text.



Directly violently generate the full permutation of 9 and then verify whether the equation holds, but when verifying, if the accuracy problem is prevented, the division can be turned into multiplication by dividing.
The answer is: 29
#include<iostream>
using namespace std;
int ans=0;
bool fish [10];
int num[9];
void solve(){
    if((num[0]+(double)num[1]/num[2]+(double)(num[3]*100+num[4]*10+num[5])/(num[6]*100+num[7]*10+num[8]))==10)
        years++;
    return;
}
void dfs(int d){
    if(d==9){
        solve();
        return;
    }
    for(int i=1;i<10;i++){
        if(!vis[i]){
            vis[i]=true;
            num[d]=i;
            dfs(d+1);
            show [i] = false;
        }
    }
}
int main(){
    dfs(0);
    cout<<ans<<endl;
return 0;
}


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325682318&siteId=291194637