|  | 
 
 发表于 2020-6-15 12:16:08
|
显示全部楼层 
| 本帖最后由 赚小钱 于 2020-6-17 10:48 编辑 
 本答案审题有误,在楼下有修改。这个回答就不改了。
 
 
 复制代码
int monkey_happy(int input) {
    return (input % 5) - 1;
}
int steal_peach(int input, int sailor_count) {
    for (int i = 0; i < sailor_count; i++) {
        int happiness = monkey_happy(input);
        if (happiness != 0) {
            return 0;
        }
        input = input / 5 - 1;
        if (input <= 0) {
            return 0;
        }
    }
    return input;
}
void steal() {
    int sailor_count = 5;
    for (int input = 6;; input++) {
        int result = steal_peach(input, sailor_count);
        if (result == 6) {
            printf("at least %d peaches!\n", input);
            return;
        }
    }
}
 1. 均分五份,藏一个,给猴子一个,等价于 count % 5 == 1; count = count / 5 - 1;
 2. 最后均分五份多一个,并且要求最少(也只能要求最少),可以得出,原有6个。
 3. 然后就是爆破。
 
 | 
 |