acdream 1704(暴力)
题意: 小晴天是ACdream团队中最牛的老师之1,他最善于数学运算~这天他翻开1本《AC is not a dream》杂志,发现最后1页有1道很经典的思惟题,题目很简单,每一个框填写1个数字,构成1个竖式,每一个数的最高位不能为0,但是有1些数字被隐藏掉了,然后让你根据没有隐藏的数字填出隐藏的数字。 以下图: 然后小晴天2话不说,3下5除2就写出了答案: 然后小晴天就觉得这样的题目太简单了,因而问你是不是有办法来求出1道题目有多少种不同的答案呢?(只要有1个方框有不同的数字即为不同的答案) 多组数据,首先是1个整数t(t<=20),表示数据组数。 对每组数据,输出1个整数x,表示符合乘法竖式法则的填法的种类。 2 ** 4** Sample Output 2 #include <stdio.h>
#include <string.h>
char str[10][10];
int s[10][10];
int res = 0,flag[5] = {3,2,4,3,5};
void solve(int x) {
for (int i = 0; i < flag[x]; i++)
if (str[x][i] != '*')
s[x][i] = str[x][i] - '0';
else
s[x][i] = -1;
}
bool judge(int x,int cur) {
int a = flag[cur] - 1,temp[10];
while (x > 0 && a >= 0) {
int b = x % 10;
if (s[cur][a] != -1 && s[cur][a] != b)
return false;
a--;
x /= 10;
}
if (x == 0 && a == -1)
return true;
return false;
}
int main() {
int t;
scanf("%d",&t);
while (t--) {
for (int i = 0; i < 5; i++) {
scanf("%s",str[i]);
solve(i);
}
res = 0;
for (int i = 100; i < 1000; i++) {
if (!judge(i,0))
continue;
for (int j = 10; j < 100; j++) {
if (!judge(j,1))
continue;
int temp1 = i * (j % 10);
if (!judge(temp1,2))
continue;
int temp2 = i * (j / 10);
if (!judge(temp2,3))
continue;
int temp = temp1 + temp2 * 10;
if (!judge(temp,4))
continue;
res++;
}
}
printf("%d
",res);
}
return 0;
} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |