A hard Aoshu Problem(hdu 3699 暴力枚举

题目:http://acm.hdu.edu.cn/showproblem.php?pid=3699

一开始用string超时了 

#include<bits/stdc++.h>
using namespace std;
char s1[10],s2[10],s3[10];
bool qdl(char s[],int a,int b,int c,int d,int e)//前导零
{
    if(strlen(s)>1&&(s[0]=='A'&&a==0||s[0]=='B'&&b==0||s[0]=='C'&&c==0||s[0]=='D'&&d==0||s[0]=='E'&&e==0))return 0;
    return 1;
}
int change(char s[],int a,int b,int c,int d,int e)//字符串 转int
{
    int q=0,p;
    for(int i=0;i<strlen(s);i++)
    {
        if(s[i]=='A')p=a;
        else if(s[i]=='B')p=b;
        else if(s[i]=='C')p=c;
        else if(s[i]=='D')p=d;
        else p=e;
        q=q*10+p;
    }
    return q;
}
int main()
{
    int a,b,c,d,e;
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s%s%s",s1,s2,s3);
        int mp[100];
        memset(mp,0,sizeof(mp));
        for(int k=0;s1[k];k++)mp[s1[k]]++;
        for(int k=0;s2[k];k++)mp[s2[k]]++;
        for(int k=0;s3[k];k++)mp[s3[k]]++;
        int cnt=0;//几个字母没出现过
        for(int i=65;i<=69;i++)if(mp[i]==0)cnt++;
        int ans=0;
        for(a=0;a<=9;a++)
        {
            for(b=0;b<=9;b++)
            {
                if(b!=a)
                {
                    for(c=0;c<=9;c++)
                    {
                        if(c!=a&&c!=b)
                        {
                            for(d=0;d<=9;d++)
                            {
                                if(d!=a&&d!=b&&d!=c)
                                {
                                    for(e=0;e<=9;e++)
                                    {
                                        if(e!=a&&e!=b&&e!=c&&e!=d)
                                        {
                                            if(qdl(s1,a,b,c,d,e)&&qdl(s2,a,b,c,d,e)&&qdl(s3,a,b,c,d,e))
                                            {
                                                int x=change(s1,a,b,c,d,e);
                                                int y=change(s2,a,b,c,d,e);
                                                int z=change(s3,a,b,c,d,e);
                                                if(x+y==z)ans++;
                                                if(x-y==z)ans++;
                                                if(x*y==z)ans++;
                                                if(y!=0&&x%y==0&&x/y==z)ans++;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        for(int i=6;i<cnt+6;i++)
        {
            ans/=i;//把没出现过的字母循环算进去了 所以除去
        }
        printf("%d\n",ans);
    }
    return 0;
}
/*
2
A A A
BCD BCD B
*/
View Code

 

转载于:https://www.cnblogs.com/ydw--/p/11370475.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值