测评机: Xeond[6]
得分: 60分
提交日期: 2012-1-19 20:14:00
有效耗时: 312毫秒
测试结果1: 通过本测试点|有效耗时78ms
测试结果2: 测试结果错误.错误结果为:no
正确结果应为:yes
测试结果3: 测试结果错误.错误结果为:no
正确结果应为:yes
测试结果4: 测试结果错误.错误结果为:no
正确结果应为:yes
测试结果5: 通过本测试点|有效耗时47ms
测试结果6: 通过本测试点|有效耗时47ms
测试结果7: 测试结果错误.错误结果为:yes
正确结果应为:no
测试结果8: 通过本测试点|有效耗时46ms
测试结果9: 通过本测试点|有效耗时47ms
测试结果10: 通过本测试点|有效耗时47ms
提交代码: view sourceprint?01.#include <cstdio>
02.#include <cstring>
03.typedef char String[20];
04.int a[4], b[4], path[4][2];
05.String ans[4], buf, Min = "zzzzz";
06.char op[4], Data[4];
07.
08.void outit() {
09.
int i;
10.
for (i = 0; i < 4; i ++)
11.
sprintf(ans[i], "%c", Data[i]);
12.
for (i = 0; i < 3; i ++) {
13.
sprintf(buf, "(%s%c%s)", ans[path[i][0]], op[i], ans[path[i][1]]);
14.
strcpy(ans[path[i][0]], buf);
15.
}
16.
if (strcmp(Min, ans[path[2][0]]) > 0)
17.
strcpy(Min, ans[path[2][0]]);
18.}
19.void dfs(int l) {
20.
if (l == 3) {
21.
int i;
22.
for (i = 0; i < 4; i ++)
23.
if (a[i] != 0) break;
24.
if (i < 4 && a[i] == 24) outit();
25.
return;
26.
}
27.
for (int i = 0; i < 4; i ++)
28.
for (int j = 0; j < 4; j ++)
29.
if (i != j && a[i] != 0 && a[j] != 0) {
30.
int t1, t2;
31.
t1 = a[i]; t2 = a[j];
32.
a[i] = a[i] + a[j]; a[j] = 0;
33.
path[l][0] = i; path[l][1] = j; op[l] = '+';
34.
dfs(l + 1);
35.
a[i] = t1; a[j] = t2;
36.
37.
t1 = a[i]; t2 = a[j];
38.
a[i] = a[i] - a[j]; a[j] = 0;
39.
path[l][0] = i; path[l][1] = j; op[l] = '-';
40.
dfs(l + 1);
41.
a[i] = t1; a[j] = t2;
42.
43.
t1 = a[i]; t2 = a[j];
44.
a[i] = a[i] * a[j]; a[j] = 0;
45.
path[l][0] = i; path[l][1] = j; op[l] = '*';
46.
dfs(l + 1);
47.
a[i] = t1; a[j] = t2;
48.
49.
if (a[i] % a[j] == 0) {
50.
t1 = a[i]; t2 = a[j];
51.
a[i] = a[i] / a[j]; a[j] = 0;
52.
path[l][0] = i; path[l][1] = j; op[l] = '/';
53.
dfs(l + 1);
54.
a[i] = t1; a[j] = t2;
55.
}
56.
}
57.}
58.int main() {
59.
char ch;
60.
memset(path, -1, sizeof(path));
61.
for (int i = 0; i < 4; i ++) {
62.
scanf("%c ", &ch);
63.
Data[i] = ch;
64.
if (ch == 'A') a[i] = 1;
65.
else if (ch == 'T') a[i] = 10;
66.
else if (ch == 'J') a[i] = 11;
67.
else if (ch == 'Q') a[i] = 12;
68.
else if (ch == 'K') a[i] = 13;
69.
else a[i] = ch - '0';
70.
}
71.
memcpy(b, a, sizeof(a));
72.
dfs(0);
73.
if (Min[0] == 'z') printf("no\n");
74.
else printf("yes\n");
75.
return 0;
76.}