zoukankan      html  css  js  c++  java
  • 马和瓦的问题

    原意:大马,中马,小马一共有100匹,一头大马拉3块瓦,一头中马拉2块瓦,3头小马拉一块瓦,一共有100块瓦.问:大马,中马,小马 各有多少只?

    用for 循环写的代码:

    public class a{
     static int c;

        public static void main(String[] args){
            m1();
        }
        public static void m1(){
            for(int d=1; d < 100; ++d){
                for(int z=1; z <100 ; ++z){
                    for(double x=1; x <100 ; ++x){
                        if (d+z+x==100 && 3*d+2*z+x/3==100) {
                            c+=1;
                            System.out.println( "第 "+ c + " 种答案 : " );
                            System.out.println( "大马 "+d+"   中马 "+z+"   小马"+x );
                        }
                    }
                }
                
            }
        }
    }

    运行结果:

    呵呵,自己没事写着玩的,写出来分享一下

  • 相关阅读:
    gitio博客搭建,hexo + NeXT
    [MIsc]JD笔试编程题
    [MATH]Big Integer +
    【Math】GCD XOR 证明
    【Math】最近点对
    【SRM】600#div2 B 枚举
    【Game】组合游戏
    【Game】找出游戏必胜态
    【DP】树形DP 记忆化搜索
    141. Linked List Cycle
  • 原文地址:https://www.cnblogs.com/xrmqbl804915256/p/4722699.html
Copyright © 2011-2022 走看看