hdu3699 A hard Aoshu Problem

10 篇文章 0 订阅

正解是DFS每种字母代表的数字

其实暴力枚举就可以了



#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <string>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <fstream>
#include <sstream>
using namespace std;

//LOOP
#define FF(i, a, b) for(int i = (a); i < (b); ++i)
#define FE(i, a, b) for(int i = (a); i <= (b); ++i)
#define FED(i, b, a) for(int i = (b); i>= (a); --i)
#define REP(i, N) for(int i = 0; i < (N); ++i)
#define CLR(A,value) memset(A,value,sizeof(A))
#define FC(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)

//INPUT
#define RI(n) scanf("%d", &n)
#define RII(n, m) scanf("%d%d", &n, &m)
#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define RS(s) scanf("%s", s)

typedef long long LL;
typedef vector <int> VI;

const int INF = 1000000007;
const double eps = 1e-10;
const int MOD = 1000000000;
const int MAXN = 10050 * 30;

int up[10], len1, len2, len3, num[10];
bool f[10];
char s1[20], s2[20], s3[20];

int fun(int a, int b, int c, int d, int e)
{
//    cout << a << b << c << d << e << endl;
    LL x, y, z; int ans;
    x = y = z = ans = 0;
    num[0] = a, num[1] = b, num[2] = c, num[3] = d, num[4] = e;
    REP(i, 5)
        FF(j, i + 1, 5)
            if (f[i] && f[j] && num[i] == num[j])
                return 0;
    REP(i, len1)
        x *= 10, x += num[s1[i] - 'A'];
    REP(i, len2)
        y *= 10, y += num[s2[i] - 'A'];
    REP(i, len3)
        z *= 10, z += num[s3[i] - 'A'];
    if (len1 > 1 && num[s1[0] - 'A'] == 0)  return 0;
    if (len2 > 1 && num[s2[0] - 'A'] == 0)  return 0;
    if (len3 > 1 && num[s3[0] - 'A'] == 0)  return 0;
    if (x + y == z) ans++;
    if (x - y == z) ans++;
    if (x * y == z) ans++;
    if (y && x == z * y) ans++;
    return ans;
}

int solve()
{
    int ans = 0;
    REP(a, up[0])
        REP(b, up[1])
            REP(c, up[2])
                REP(d, up[3])
                    REP(e, up[4])
                        ans += fun(a, b, c, d, e);
    return ans;
}

int main()
{
    int T;
    RI(T);
    while (T--)
    {
        RS(s1), RS(s2), RS(s3);
        CLR(f, 0);
        len1 = strlen(s1), len2 = strlen(s2), len3 = strlen(s3);
        REP(i, strlen(s1))
            f[s1[i] - 'A'] = 1;
        REP(i, strlen(s2))
            f[s2[i] - 'A'] = 1;
        REP(i, strlen(s3))
            f[s3[i] - 'A'] = 1;
        REP(i, 5)
            if (f[i])   up[i] = 10;
            else    up[i] = 1;
        cout << solve() << endl;
    }
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值