2016年第七届蓝桥杯 凑算式(结果填空题)

Problem  Description:

如图,这个算式中A~I代表1~9的数字,不同的字母代表不同的数字。


比如:
6+8/3+952/714 就是一种解法,
5+3/1+972/486 是另一种解法。


问:这个算式一共有多少种解法?

答案:29

1.思路:首先提供一个简便且不会出错的方法,将除法转换成乘法就不用考虑有小数的问题了,即a+b/c+d/e=10 \Rightarrow a*c*e+b*e+d*c=10*c*e,其次,九个数用全排列方式列出所有可能。

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
int main()
{
    int a[9] = {1,2,3,4,5,6,7,8,9};
    int ans = 0;
    do
    {
        if(a[0]*a[2]*(a[6]*100+a[7]*10+a[8]) + a[1]*(a[6]*100+a[7]*10+a[8]) + (a[3]*100+a[4]*10+a[5])*a[2] == 10*(a[6]*100+a[7]*10+a[8])*a[2])
            ans ++;
    }while(next_permutation(a,a+9));///全排列
    cout << ans << endl;
}

2.思路:暴力,9个for循环,但是这里一定要注意题意,“不同的字母代表不同的数字” 意思就是每个式子中不会有相同的数字出现,这点很重要,因为这是填空题,题意理解错了就一分儿也没了。(这题没说952/714是要整数部分还是整数、小数的都要,所以我就2种都试了一下,发现答案一样,不影响)

#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<string.h>
#include<math.h>
using namespace std;
typedef long long ll;
int main()
{
    double a,b,c,d,e,f,g,h,i;
    //int a,b,c,d,e,f,g,h,i;
    int cnt = 0;
    for(a = 1; a <= 9; a++)
    {
        for(b = 1; b <= 9; b++)
        {
            if(a == b) continue;
            for(c = 1; c < 10; c++)
            {
                if(b == c || a == c) continue;
                for(d = 1; d < 10; d++)
                {
                    if(c == d || a == d || b == d) continue;
                    for(e = 1; e < 10; e++)
                    {
                        if(d == e || a == e || b == e || c == e) continue;
                        for(f = 1; f < 10; f++)
                        {
                            if(e == f || a == f || b == f || c == f || d == f) continue;
                            for(g = 1; g < 10; g++)
                            {
                                if(f == g || a == g || b == g || c == g || d == g || e == g) continue;
                                for(h = 1; h <10; h++)
                                {
                                    if(g == h || a == h || b == h || c == h || d == h || e == h || f == h) continue;
                                    for(i = 1; i < 10; i++)
                                    {
                                        if(h == i || i == a || b == i || c == i || d == i || e == i || f == i || g == i) continue;
                                        if(a+b/c+(d*100+e*10+f)/(g*100+h*10+i) == 10)
                                            cnt++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    cout << cnt <<endl;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值