classic problem: 100 horse and 100 dan

public class HorseDan {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        // 100 horses, 100 dan
        // big horse 3, mid 2, small 1/2
       
        int totalWays = 0;
       
        for (int i=1; i<33; i++) {
            for (int j=1; j<50; j++) {
                int k = 100 - i - j;
                if (k%2 == 0) {
                    if (i*3 + j*2 + k/2 == 100) {
                        totalWays++;
                        System.out.print("big: " + i + ",");
                        System.out.print("mid: " + j + ",");
                        System.out.print("small: " + k);
                        System.out.println();
                    }   
                }
            }   
        }

  
        System.out.println("totalWays: " + totalWays);


    }
}

原文地址:https://www.cnblogs.com/tiechui/p/1898835.html