HDU 4403 A very hard Aoshu problem 第37届ACM/ICPC 金华赛区网络赛1004题

A very hard Aoshu problem

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

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  

 

Source
2012 ACM/ICPC Asia Regional Jinhua Online  

 

Recommend zhoujiaqi2010     这题就是超级简单的水题。 暴搜就可以了。 只有一个等号,多个加号。 很简单。 ps:今天网络太晕了。。。。明天求给力!

//1004
#include<stdio.h>
#include<iostream>
#include<map>
#include<set>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
using namespace std;

int a[20];
int n;

bool solve(int s1,int s2,int t)
{
    int aa,b;
    aa=0;
    b=0;
    int temp=a[1];
    int p=1;
    for(int i=1;i<t;i++)
    {
        if(s1&(1<<(i-1)))
        {
            aa+=temp;
            temp=a[i+1];
        }
        else
        {
            temp*=10;
            temp+=a[i+1];
        }
    }
    aa+=temp;
    temp=a[t+1];
    for(int i=t+1;i<n;i++)
    {

        int qq=i-t-1;
        if(s2&(1<<qq))
        {
            b+=temp;
            temp=a[i+1];
        }
        else
        {
            temp*=10;
            temp+=a[i+1];
        }
    }
    b+=temp;
    if(aa==b)return true;
    else return false;
}
char str[30];
int main()
{
    //freopen("D.in","r",stdin);
   // freopen("D.out","w",stdout);
    while(scanf("%s",&str))
    {
        if(strcmp(str,"END")==0)break;
        int ans=0;
        n=strlen(str);
        for(int i=0;i<n;i++)
           a[i+1]=str[i]-'0';
        for(int i=1;i<n;i++)
        {
            int t1=(1<<(i-1));
            int t2=(1<<(n-i-1));
            for(int s1=0;s1<t1;s1++)
              for(int s2=0;s2<t2;s2++)
                if(solve(s1,s2,i))
                   ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

    原文作者:算法小白
    原文地址: https://www.cnblogs.com/kuangbin/archive/2012/09/22/2698422.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞