solution.md 3.1 KB
Newer Older
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
# 比酒量
有一群海盗(不多于20人),在船上比拼酒量。过程如下:打开一瓶酒,所有在场的人平分喝下,有几个人倒下了。再打开一瓶酒平分,又有倒下的,
再次重复...... 

直到开了第4瓶酒,坐着的已经所剩无几,海盗船长也在其中。当第4瓶酒平分喝下后,大家都倒下了。

等船长醒来,发现海盗船搁浅了。他在航海日志中写到:“......昨天,我正好喝了一瓶.......奉劝大家,开船不喝酒,喝酒别开船......”

请你根据这些信息,推断开始有多少人,每一轮喝下来还剩多少人。

如果有多个可能的答案,请列出所有答案,每个答案占一行。

格式是:人数,人数,...

例如,有一种可能是:```20,5,4,2,0```



## aop
### before
```cpp
#include <cstdio>
#include <iostream>
using namespace std;
int d, a1[4];
```
### after
```cpp
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;
}
```

## 答案
```cpp
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];
    }
    for (int i = 1; i < 4; i++)
    {
        sum += (a1[0] / a1[i]);
    }
    return sum + ss;
}
```
## 选项

### A
```cpp
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];
    }
    for (int i = 1; i <= 4; i++)
    {
        sum += (a1[0] / a1[i]);
    }
    return sum + ss;
}
```

### B
```cpp
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];
    }
    for (int i = 1; i <= 4; i++)
    {
        sum += (a1[0] / a1[i]);
    }
    return sum + ss;
}
```

### C
```cpp
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;
}
```