zoukankan      html  css  js  c++  java
  • java算法 第七届 蓝桥杯B组(题+答案) 3.凑算式

    3.凑算式  (结果填空)

         B      DEF
    A + --- + ------- = 10
         C      GHI
             
    (如果显示有问题,可以参见【图1.jpg】)
     
    这个算式中A~I代表0~9的数字,不同的字母代表不同的数字。

    比如:
    6+8/3+952/714 就是一种解法,
    5+3/1+972/486 是另一种解法。
    这个算式一共有多少种解法?
    注意:你提交应该是个整数,不要填写任何多余的内容或说明性文字。

    提醒:此题虽然可以用暴力破解去解决,但是要注意DEF和GHI分别是一个三位数,不能拆开当成一个个数字去乘;还有为了避免分母不为0的情况尽量将分式转化为整式。(或者B和DEF乘以1.0转化为double,然后可以直接除以C和GHI了)

     1 public class _3凑算式 {
     2     public static void main(String[] args) {
     3         int sum = 0;
     4         for (int a = 1; a < 10; a++) {
     5             for (int b = 1; b < 10; b++) {
     6                 for (int c = 1; c < 10; c++) {
     7                     for (int d = 1; d < 10; d++) {
     8                         for (int e = 1; e < 10; e++) {
     9                             for (int f = 1; f < 10; f++) {
    10                                 for (int g = 1; g < 10; g++) {
    11                                     for (int h = 1; h < 10; h++) {
    12                                         for (int i = 1; i < 10; i++) {
    13                     if ((a!=b&&a!=c&&a!=d&&a!=e&&a!=f&&a!=g&&a!=h&&a!=i)&&
    14                             (b!=c&&b!=d&&b!=e&&b!=f&&b!=g&&b!=h&&b!=i)&&
    15                             (c!=d&&c!=e&&c!=f&&c!=g&&c!=h&&c!=i)&&
    16                             (d!=e&&d!=f&&d!=g&&d!=h&&d!=i)&&
    17                             (e!=f&&e!=g&&e!=h&&e!=i)&&
    18                             (f!=g&&f!=h&&f!=i)&&
    19                             (g!=h&&g!=i)&&
    20                             (h!=i)) {
    21                         int shang = d*100+e*10+f;
    22                         int xia = g*100+h*10+i;
    23                         if (((a*c*xia)+(b*xia)+(shang*c)) -(10*c*xia) ==0) {
    24                             sum++;
    25                         }
    26                     }                    
    27                                         }
    28                                         
    29                                     }
    30                                     
    31                                 }
    32                                 
    33                             }
    34                             
    35                         }
    36                     }
    37                 }
    38                 
    39             }
    40         }
    41         System.out.println(sum);
    42     }
    43 }

    运行结果:29

  • 相关阅读:
    toj 2975 Encription
    poj 1797 Heavy Transportation
    toj 2971 Rotating Numbers
    zoj 2281 Way to Freedom
    toj 2483 Nasty Hacks
    toj 2972 MOVING DHAKA
    toj 2696 Collecting Beepers
    toj 2970 Hackle Number
    toj 2485 Card Tric
    js页面定位,相关几个属性
  • 原文地址:https://www.cnblogs.com/zhangxue521/p/6538487.html
Copyright © 2011-2022 走看看