# 比酒量 有一群海盗(不多于20人),在船上比拼酒量。过程如下:打开一瓶酒,所有在场的人平分喝下,有几个人倒下了。再打开一瓶酒平分,又有倒下的, 再次重复...... 直到开了第4瓶酒,坐着的已经所剩无几,海盗船长也在其中。当第4瓶酒平分喝下后,大家都倒下了。 等船长醒来,发现海盗船搁浅了。他在航海日志中写到:“......昨天,我正好喝了一瓶.......奉劝大家,开船不喝酒,喝酒别开船......” 请你根据这些信息,推断开始有多少人,每一轮喝下来还剩多少人。 如果有多个可能的答案,请列出所有答案,每个答案占一行。 格式是:人数,人数,... 例如,有一种可能是:```20,5,4,2,0``` 以下错误的一项是? ## aop ### before ```cpp #include using namespace std; ``` ### after ```cpp ``` ## 答案 ```cpp int d, a1[4]; int d1(int *a1) { int sum = a1[0]; for (int i = 1; i < 4; i++) { if (sum % a1[i] != 0) return i; } return 0; } int getS(int *a1) { int sum = 0, ss = 1; while (d1(a1) != 0) { int index = d1(a1); a1[0] = a1[0] * a1[index]; ss = a1[index]; sum += ss; } return sum; } int main() { for (int sum = 20; sum >= 1; sum--) { for (int a = 1; a <= 20; a++) { for (int b = 1; b <= 20; b++) { for (int c = 1; c <= 20; c++) { a1[0] = sum, a1[1] = a, a1[2] = b, a1[3] = c; if (getS(a1) == a1[0] && a > b && b > c && sum > a) { printf("%d, %d, %d, %d, 0\n", sum, a, b, c); } } } } } return 0; } ``` ## 选项 ### A ```cpp int main() { float n; float a, b, c; float s1, s2, s3; for (n = 5; n <= 20; n++) { for (a = 1; a <= n; a++) for (b = 1; b <= n; b++) for (c = 1; c <= n; c++) { s1 = n - a; s2 = n - a - b; s3 = n - a - b - c; if (1 / n + 1 / s1 + 1 / s2 + 1 / s3 == 1 && s1 > 0 && s2 > 0 && s3 > 0) cout << n << "," << s1 << "," << s2 << "," << s3 << "," << "0" << endl; } } return 0; } ``` ### B ```cpp int cm(int a, int b) { int temp; int mul; mul = a * b; if (a % b == 0) return a; else { while (a % b != 0) { temp = a % b; a = b; b = temp; } return mul * b; } } int main() { int a, b, c, d; int temp; int ta, tb, tc, td; for (a = 20; a >= 5; a--) for (b = a - 1; b >= 4; b--) for (c = b - 1; c >= 3; c--) for (d = c - 1; d >= 2; d--) { temp = cm(a, b); temp = cm(temp, c); temp = cm(temp, d); ta = temp / a; tb = temp / b; tc = temp / c; td = temp / d; if (ta + tb + tc + td == temp) cout << a << "," << b << "," << c << "," << d << "," << "0" << endl; } return 0; } ``` ### C ```cpp int main(void) { float a, b, c, d; float x, y, z, m; for (x = 20; x >= 5; x--) { for (y = x - 1; y >= 4; y--) { for (z = y - 1; z >= 3; z--) { for (m = y - 1; m >= 2; m--) { if (y * z * m + x * z * m + x * y * m + x * y * z == x * y * z * m) { cout << x << "," << y << "," << z << "," << m << "," << "0" << endl; } } } } } } ```