zoukankan      html  css  js  c++  java
  • [蓝桥杯] 凑算式

    [蓝桥杯] 凑算式

    【题目描述 - Problem Description】

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

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

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

    【题解】

      使用全排列暴力枚举
      坑点在于这里是数学的除法,不是计算机整数除法。
      可以转为乘法从而避免精度问题。

    【最终结果】

    29

    【代码 C++】

     1 #include <cstdio>
     2 #include <algorithm>
     3 int data[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
     4 int main() {
     5     int a, b, c, d, g, i, opt = 0;
     6     do{
     7         a = data[0];
     8         b = data[1];
     9         c = data[2];
    10         for (d = 0, i = 3; i < 6; ++i) d = d * 10 + data[i];
    11         for (g = 0, i = 6; i < 9; ++i) g = g * 10 + data[i];
    12         if (a*c*g + b*g + d*c == 10 * c*g) ++opt;
    13     } while (std::next_permutation(data, data + 9));
    14     printf("%d", opt);
    15     return 0;
    16 }
  • 相关阅读:
    hive参数配置及任务优化
    python基础篇_002_基础数据类型
    python基础篇_001_初识Python
    Java 修饰符
    Java 构造代码块
    Java static 关键字
    Java 继承
    37 自定义异常
    36 异常
    35 异常
  • 原文地址:https://www.cnblogs.com/Simon-X/p/6516326.html
Copyright © 2011-2022 走看看