USACO 1.3 Prime Cryptarithm

来源:互联网 发布:沥青路面厚度设计软件 编辑:程序博客网 时间:2024/06/06 03:45

直接穷举搜索,剪枝。 不想剪了,反正不会TLE。


/*TASK:crypt1LANG:C++*/#include <iostream>#include <cstdio>using namespace std;int n, ans(0);int a[10];int b[100]={0};int main(){freopen("crypt1.in", "r", stdin);freopen("crypt1.out", "w", stdout);cin >> n;for (int i = 0; i != n; ++ i){cin>>a[i];b[a[i]] = 1;}for (int i = 0 ; i != n; ++ i){if (!a[i])continue;for (int j = 0; j != n; ++ j)for (int k = 0; k != n; ++ k)for (int l = 0; l != n; ++ l) //个位{if (!a[l])continue;int x, y, z;z = a[l] * a[k];y = z / 10;z %= 10;if (!b[z])continue;y += a[l] * a[j];x = y / 10;y %= 10;if (!b[y])continue;x += a[l] * a[i];if (!b[x])continue;for (int m = 0; m != n; ++ m){int x1, y1,z1;z1 = a[m] * a[k];y1 = z1 / 10;z1 %= 10;if (!b[z1])continue;y1 += a[m] * a[j];x1 = y1 / 10;y1 %= 10;if (!b[y1])continue;x1 += a[m] * a[i];if (!b[x1])continue;int tmp1 = (y + z1) % 10;if (!b[tmp1])continue;tmp1 = (y + z1) / 10 + x + y1;int tmp2 = tmp1 % 10;if (!b[tmp2])continue;if (!b[tmp1 / 10 + x1])continue;++ ans;}}}cout<< ans <<endl;return 0;}


0 0
原创粉丝点击