解题思路:

开始以为是一道动态规划,结果是贪心(此题是找规律)

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int res = 1;
        int cur = 1;
        int total = 1;

        while (total < n) {
            res++;
            cur *= 3;
            total += cur;
        }
        System.out.print(res);
    }
}

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐