2012年9月22日 金华网络预赛 D题 结题报告——子集划分,数学




A very hard Aoshu problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
Aoshu is very popular among primary school students. It is mathematics, but much harder than ordinary mathematics for primary school students. Teacher Liu is an Aoshu teacher. He just comes out with a problem to test his students:

Given a serial of digits, you must put a '=' and none or some '+' between these digits and make an equation. Please find out how many equations you can get. For example, if the digits serial is "1212", you can get 2 equations, they are "12=12" and "1+2=1+2". Please note that the digits only include 1 to 9, and every '+' must have a digit on its left side and right side. For example, "+12=12", and "1++1=2" are illegal. Please note that "1+11=12" and "11+1=12" are different equations.
 

Input
There are several test cases. Each test case is a digit serial in a line. The length of a serial is at least 2 and no more than 15. The input ends with a line of "END".
 

Output
For each test case , output a integer in a line, indicating the number of equations you can get.
 

Sample Input
  
  
1212 12345666 1235 END
 

Sample Output
  
  
2 2 0
 




#include <algorithm>

#include <iostream>
#include <iomanip>
#include <string>

#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>

#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <set>
#include <bitset>

using namespace std;

char s[100];

template<
    class Key,
    class Compare = std::less<Key>,
    class Allocator = std::allocator<Key>
> class multiset;


map <__int64, int > s1;
map <__int64, int > s2;

__int64 mypow(int x, int y)
{
    __int64 t;
    if (y == 0)
        return 1;
    else if (y == 1)
        return x;
    else if (y == 2)
        return x * x;
    else if (y % 2)
    {
        t = mypow(x, (y - 1) / 2);
        return t * t * x;
    }

    else
    {
        t = mypow(x ,y / 2);
        return t * t;
    }
}

void f(map <__int64, int> &ss, int l, int h)
{
    int i, j, k, p, t[100];
    __int64 num, n;

    n = 0;
    p = 0;
    for (i = (1 << (h - l)) - 1; i >= 0; i--)
    {
        num = 0;
        for (j = 0; j < (h - l); j++)
        {
            if (i & (1 << j))
            {
                n = 0;
                t[p++] = (int) (s[h - j] - 48);
                for (k = 0; k < p; k++)
                {
                    n += (t[k] * mypow(10, k));
                }
                num += n;
                n = 0;
                p = 0;
            }

            else
            {
                t[p] =  (int)(s[h-j]  - 48);
                p++;
            }
        }

        t[p++] = (int)(s[l]  - 48);

        for (k = 0; k < p; k++)
        {
            n += (t[k] * mypow(10,  k));
        }
        num+= n;
//        ss.insert(num);
        ss[num]++;
        p = 0;
        n = 0;
        num = 0;
    }

}


int main()
{
    int ans, len, j;
    map <__int64, int> :: iterator it;
    map <__int64, int> :: iterator it2;
    scanf("%s", s);
    while ( strcmp(s, "END") != 0)
    {
        ans = 0;
        len = strlen(s);

        for (j = 1; j <= len - 1; j++)
        {
            s1.clear();
            s2.clear();
            f(s1, 0, j - 1);

            f(s2, j, len - 1);

            for (it = s1.begin(); it != s1.end(); it++)
            {

                for (it2 = s2.begin(); it2 != s2.end(); it2++)
                {
                    if (it ->first == it2 -> first)
                    {
                        ans += it -> second * it2 -> second;
                        break;
                    }
                }




            }
        }

        printf("%d\n", ans);
        scanf("%s", s);
    }

    //system("pause");
    return 0;
}





子集划分!

有不懂就留言吧!







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值