有一群海盗(不多于20人),在船上比拼酒量。过程如下:打开一瓶酒,所有在场的人平分喝下,有几个人倒下了。再打开一瓶酒平分,又有倒下的,再次重复...... 直到开了第4瓶酒,坐着的已经所剩无几,海盗船长也在其中。当第4瓶酒平分喝下后,大家都倒下了。
等船长醒来,发现海盗船搁浅了。他在航海日志中写到:“......昨天,我正好喝了一瓶.......奉劝大家,开船不喝酒,喝酒别开船......”
请你根据这些信息,推断开始有多少人,每一轮喝下来还剩多少人。
如果有多个可能的答案,请列出所有答案,每个答案占一行。
格式是:人数,人数,...
例如,有一种可能是:20,5,4,2,0
答案写在“解答.txt”中,不要写在这里!
20,5,4,2,0
18,9,3,2,0
15,10,3,2,0
12,6,4,2,0
多种方法实现:
package detail_03;
public class CapacityOfLiquor_01 {
int[] remain = new int[4];
public void method_02(int n,int count,double captain) {
captain =captain+(double)(1/(double)n);
count--;
remain[3-count] = n;
int limit = count;
if (count == 0) {
if (captain == 1)
printResult(remain);
return;
} else
for (int i = limit; i < n; i++) {
method_02(i,count,captain);
}
}
private void printResult(int[] array) {
// TODO Auto-generated method stub
for (int i = 0; i < array.length; i++)
System.out.print(array[i] + ",");
System.out.println("0");
}
public static void method_01() {
int n, a, b, c;
for (n = 20; n >= 4; n--)
for (a = 3; a < n; a++)
for (b = 2; b < a; b++)
for (c = 1; c < b; c++) {
if (a * b * c + n * b * c + n * a * c + n * a * b == n
* a * b * c)
System.out.println(n + "," + a + "," + b + "," + c
+ "," + 0);
else
continue;
}
}
public static void main(String[] args) {
CapacityOfLiquor_01 cl = new CapacityOfLiquor_01();
for (int i = 20; i >= 4; i--)
cl.method_02(i,4,0);
// method_01();
}
}
/*
* 20,5,4,2,0 18,9,3,2,0 15,10,3,2,0 12,6,4,2,0
*/