【HDOJ】4403 A very hard Aoshu problem

HASH+暴力。

 1 /* 4403 */
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <cstdlib>
 6 #include <map>
 7 using namespace std;
 8 
 9 #define MAXN 55
10 
11 map<int, int> tb[2];
12 char s[MAXN];
13 
14 int get(int b, int e) {
15     int ret = 0;
16 
17     for (int i=b; i<e; ++i)
18         ret = 10*ret + s[i] - '0';
19 
20     return ret;
21 }
22 
23 void myfill(int b, int e, int v, int in) {
24     int tmp = 0;
25 
26     if (b == e)
27         tb[in][v]++;
28 
29     for (int i=b; i<e; ++i) {
30         tmp = 10 * tmp + s[i] - '0';
31         myfill(i+1, e, v+tmp, in);
32     }
33 }
34 
35 int main() {
36     int len;
37     int i, j, k, tmp;
38     int x, y;
39     int ans;
40 
41     #ifndef ONLINE_JUDGE
42         freopen("data.in", "r", stdin);
43     #endif
44 
45     while (scanf("%s", s)!=EOF && s[0]!='E') {
46         len = strlen(s);
47         ans = 0;
48         for (i=1; i<len; ++i) {
49             tb[0].clear();
50             tb[1].clear();
51             myfill(0, i, 0, 0);
52             myfill(i, len, 0, 1);
53             for (map<int, int>::iterator iter=tb[0].begin(); iter!=tb[0].end(); iter++)
54                 ans += iter->second * tb[1][iter->first];
55         }
56         printf("%d\n", ans);
57     }
58 
59     return 0;
60 }

 

posted on 2015-01-02 04:14  Bombe  阅读(186)  评论(0编辑  收藏  举报

导航