ACC

任晟麒  •  1个月前


#include<cstdio>
using namespace std;

int main(){
    int apples; // 复用:①当前剩余苹果总数 ②目标苹果(最后一个)的当前序号
    scanf("%d", &apples);   

    int total_days = 0;  // 拿完所有苹果的总天数
    int target_day = 0;  // 最后一个苹果被拿走的天数

    while(apples > 0){
        total_days++; // 每一天计数+1
        
        // 仅当目标未找到,且当前序号%3==1(被拿走)时,记录天数
        if(target_day == 0 && apples % 3 == 1){
            target_day = total_days;
        }
        
        // 更新剩余苹果数:总数 - 当天被拿走的数量(向上取整)
        apples -= (apples + 2) / 3;
    }  

    printf("%d %d\n", total_days, target_day);
    return 0;
}

评论:

请先登录,才能进行评论