Similar fill-in-the-blank questions:
①Equation 900:
https://blog.csdn.net/s44Sc21/article/details/132746513?spm=1001.2014.3001.5501https://blog.csdn.net/s44Sc21/article/details/132746513?spm=1001.2014.3001.5501
②Nine Palaces Magic Square ③Seven Stars Fill in the Numbers ④Magic Square Fill in the Blanks:
https://blog.csdn.net/s44Sc21/article/details/132429826?spm=1001.2014.3001.5501 https://blog.csdn.net/s44Sc21/article/ details/132429826?spm=1001.2014.3001.5501
⑤Solitaire triangle:
⑥Building blocks:
https://blog.csdn.net/s44Sc21/article/details/132840321?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22 %3A%22132840321%22%2C%22source%22%3A%22s44Sc21%22%7D https://blog.csdn.net/s44Sc21/article/details/132840321?csdn_share_tail=%7B%22type%22%3A%22blog %22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22132840321%22%2C%22source%22%3A%22s44Sc21%22%7D ⑦ Fill in the number of five stars :
Question description
This question is a fill-in-the-blank question. You only need to calculate the result and use the output statement in the code to output the filled-in result.
B DEF
A + --- + ------- = 10
C GHI
In this formula, A ~ I represent numbers from 0 to 9, and different letters represent different numbers.
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?
operating restrictions
- Maximum running time: 1s
- Maximum running memory: 128M
import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改
public class Main {
static int[] a=new int[9];
static int[] biaoji=new int[10];
static int ans=0;
static int flag=0;
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
//在此输入您的代码...
scan.close();
dfs(0);
System.out.println(ans);
}
public static void dfs(int n){
if(n==9){
int A=a[0];
int B=a[1];
int C=a[2];
int D=a[3]*100+a[4]*10+a[5];
int E=a[6]*100+a[7]*10+a[8];
if((A+B*1.0/+C+D*1.0/E)==10){
ans++;
return;
}
else{
return;
}
}
if(a[n]!=0){
dfs(n+1);
}
for(int i=1;i<=9;i++){
if(biaoji[i]==0&&a[n]==0){
biaoji[i]=1;
a[n]=i;
dfs(n+1);
biaoji[i]=0;
a[n]=0;
}
}
}
}