1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| public class Main { public static int[][] f() { int k, row = 1; int[][] ans = new int[20][3]; for (int i = 1; i < 20; i++) { for (int j = 1; j < 33; j++) { k = 100 - i - j; if ((k % 3 == 0) && (5 * i + 3 * j + k / 3 == 100)) { ans[row][0] = i; ans[row][1] = j; ans[row][2] = k; row++; } } } ans[0][0] = row; return ans; }
public static void main(String[] args) { int[][] ans = f(); for (int i = 1; i < ans[0][0]; i++) { System.out.println("公鸡" + ans[i][0] + "只,母鸡" + ans[i][1] + "只,小鸡" + ans[i][2] + "只"); System.out.println(); } if (ans[0][0] == 0) { System.out.println("本题无解!"); } } }
|