标签:
1 /*
2 暴力:纯暴力,在家水水
3 */
4 #include <cstdio>
5 #include <cstring>
6 #include <algorithm>
7 #include <iostream>
8 #include <string>
9 #include <vector>
10 #include <cmath>
11 using namespace std;
12
13 const int MAXN = 1e3 + 10;
14 const int INF = 0x3f3f3f3f;
15 char s[15];
16 int v[15];
17 int len, tar;
18
19 bool cmp(int x, int y) {return x > y;}
20
21 void work(void)
22 {
23 for (int i=0; i<len; ++i)
24 {
25 for (int j=0; j<len; ++j)
26 {
27 if (i != j)
28 {
29 for (int k=0; k<len; ++k)
30 {
31 if (k != i && k != j)
32 {
33 for (int l=0; l<len; ++l)
34 {
35 if (l != i && l != j && l != k)
36 {
37 for (int m=0; m<len; ++m)
38 {
39 if (m != i && m != j && m != k && m != l)
40 {
41 if (v[i] - pow (v[j], 2) + pow (v[k], 3) - pow (v[l], 4) + pow (v[m], 5) == tar)
42 {
43 printf ("%c%c%c%c%c\n", v[i] + ‘A‘ - 1, v[j] + ‘A‘ - 1, v[k] + ‘A‘ - 1, v[l] + ‘A‘ - 1, v[m] + ‘A‘ - 1);
44 return ;
45 }
46 }
47 }
48 }
49 }
50 }
51 }
52 }
53 }
54 }
55
56 printf ("no solution\n");
57 }
58
59 int main(void) //ZOJ 1403 Safecracker
60 {
61 // freopen ("ZOJ_1403.in", "r", stdin);
62
63 while (scanf ("%d%s", &tar, &s) == 2)
64 {
65 if (tar == 0 && strcmp (s, "END") == 0) break;
66 len = strlen (s);
67 for (int i=0; i<len; ++i) v[i] = s[i] - ‘A‘ + 1;
68 sort (v, v+len, cmp);
69
70 work ();
71 }
72
73 return 0;
74 }
75
76
77 /*
78 v - w^2 + x^3 - y^4 + z^5 = target
79 */
标签:
原文地址:http://www.cnblogs.com/Running-Time/p/4631901.html