zoukankan      html  css  js  c++  java
  • HDU3699 A hardaosu Problem

                            #define DeBUG
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstdlib>
    #include <algorithm>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <string>
    #include <set>
    #include <sstream>
    #include <map>
    #include <bitset>
    using namespace std ;
    #define zero {0}
    #define INF 2000000000
    #define EPS 1e-6
    typedef long long LL;
    const double PI = acos(-1.0);
    inline int sgn(double x){return fabs(x) < EPS ? 0 :(x < 0 ? -1 : 1);}
    const int MAXN=12;
    char s1[MAXN];
    char s2[MAXN];
    char s3[MAXN];
    int trans[MAXN];
    bool exist[MAXN],use[MAXN];
    int ans;
    int s_to_i(char *s)
    {
        if(trans[s[0]-'A']==0&&s[1])return -1;
        int ret=0;
        for(int i=0;s[i];i++)
        {
            ret=ret*10+trans[s[i]-'A'];
        }
        return ret;
    }
    void dfs(int dep)
    {
        if(dep==5)
        {
            int a1=s_to_i(s1);
            int a2=s_to_i(s2);
            int a3=s_to_i(s3);
            if(a1==-1||a2==-1||a3==-1)return;
            if(a1+a2==a3)++ans;
            if(a1-a2==a3)++ans;
            if(a1*a2==a3)++ans;
            if(a2&&a1==a2*a3)++ans;
            return;
        }
        if(!exist[dep])
        {
            dfs(dep+1);
            return;
        }
        for(int i=0;i<10;i++)
        {
            if(use[i])
                continue;
            trans[dep]=i;
            use[i]=true;
            dfs(dep+1);
            use[i]=false;
        }
    }
    void check(char *s)
    {
        for(int i=0;s[i];i++)
        {
            exist[s[i]-'A']=true;
        }
    }
    int main()
    {    
        #ifdef DeBUG
            freopen("C:\Users\Sky\Desktop\1.in","r",stdin);
        #endif
        int T;
        scanf("%d", &T);
        while(T--)
        {
            scanf("%s%s%s", s1,s2,s3);
            memset(exist,0,sizeof(exist));
            check(s1),check(s2),check(s3);
            ans=0;
            dfs(0);
            printf("%d
    ", ans);
        }
        
        return 0;
    }
    View Code

    A hard Aoshu Problem

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

    Problem Description
    Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. Nowadays, Aoshu is getting more and more difficult. Here is a classic Aoshu problem:
    ABBDE __ ABCCC = BDBDE
    In the equation above, a letter stands for a digit(0 – 9), and different letters stands for different digits. You can fill the blank with ‘+’, ‘-‘ , ‘×’ or ‘÷’.
    How to make the equation right? Here is a solution:
    12245 + 12000 = 24245
    In that solution, A = 1, B = 2, C = 0, D = 4, E = 5, and ‘+’ is filled in the blank.
    When I was a kid, finding a solution is OK. But now, my daughter’s teacher tells her to find all solutions. That’s terrible. I doubt whether her teacher really knows how many solutions are there. So please write a program for me to solve this kind of problems.
     
    Input
    The first line of the input is an integer T( T <= 20) indicating the number of test cases.
    Each test case is a line which is in the format below:
    s1 s2 s3
    s1, s2 and s3 are all strings which are made up of capital letters. Those capital letters only include ‘A’,’B’,’C’,’D’ and ‘E’, so forget about ‘F’ to ‘Z’. The length of s1,s2 or s3 is no more than 8.
    When you put a ‘=’ between s2 and s3, and put a operator( ‘+’,’-‘, ‘×’ or ‘÷’.) between s1 and s2, and replace every capital letter with a digit, you get a equation.
    You should figure out the number of solutions making the equation right.
    Please note that same letters must be replaced by same digits, and different letters must be replaced by different digits. If a number in the equation is more than one digit, it must not have leading zero.
     
    Output
    For each test case, print an integer in a line. It represents the number of solutions.
     
    Sample Input
    2 A A A BCD BCD B
     
    Sample Output
    5 72
     
    Source
     
    Recommend
    chenyongfu   |   We have carefully selected several similar problems for you:  3697 3696 3695 3698 3692 
     
  • 相关阅读:
    [NSURL initFileURLWithPath:]: nil string parameter 错误的解决方案
    Parser Error Message: Could not load type 错误原因
    C# DropDownList做友情链接打开新窗口
    前两天去A公司面试,面试管问的题目一下子闷了。很郁闷。重新答题。在这里分享一下
    获取枚举描述信息(Description)
    生成实体层的界面(webForm1.aspx)代码
    java中Filter 技术
    hdu_1332&poj_1102_LCDisplay
    hdu_1997_汉诺塔VII
    hdu_1134_Game of Connections_卡特兰数列
  • 原文地址:https://www.cnblogs.com/Skyxj/p/3386504.html
Copyright © 2011-2022 走看看