Posted on 2009-03-18 19:44
superman 阅读(131)
评论(0) 编辑 收藏 引用 所属分类:
USACO
1 #include <iostream>
2
3 using namespace std;
4
5 bool find(int x[], int n, int m)
6 {
7 for (int i = 0; i < n; i++)
8 if (x[i] == m)
9 return true;
10 return false;
11 }
12
13 int main()
14 {
15 freopen("crypt1.in", "r", stdin);
16 freopen("crypt1.out", "w", stdout);
17
18 int n, x[10];
19
20 cin >> n;
21 for (int i = 0; i < n; i++)
22 cin >> x[i];
23
24 /*
25 a b c
26 x p q
27 -------
28 * * * == i
29 * * * == j
30 -------
31 * * * * == k
32 */
33 int ans = 0;
34 for (int a = 0; a < n; a++)
35 for (int b = 0; b < n; b++)
36 for (int c = 0; c < n; c++)
37 for (int p = 0; p < n; p++)
38 for (int q = 0; q < n; q++)
39 {
40 int i = (x[a] * 100 + x[b] * 10 + x[c]) * x[q];
41 int j = (x[a] * 100 + x[b] * 10 + x[c]) * x[p] * 10;
42 int k = i + j;
43
44 if (i >= 1000 || j >= 10000 || k >= 10000)
45 continue;
46 else
47 {
48 //check i
49 if (find(x, n, i / 1 % 10) == false ||
50 find(x, n, i / 10 % 10) == false ||
51 find(x, n, i / 100 % 10) == false)
52 continue;
53 //check j
54 if (find(x, n, j / 10 % 10) == false ||
55 find(x, n, j / 100 % 10) == false ||
56 find(x, n, j / 1000 % 10) == false)
57 continue;
58 //check k
59 if (find(x, n, k / 1 % 10) == false ||
60 find(x, n, k / 10 % 10) == false ||
61 find(x, n, k / 100 % 10) == false ||
62 find(x, n, k / 1000 % 10) == false)
63 continue;
64 ans += 1;
65 }
66 }
67
68 cout << ans << endl;
69
70 return 0;
71 }
72