B3629 吃冰棍 时间复杂度O(log_3 N)过

· · 题解

题目传送门

K换1的复杂度为O(log_K N),本题K=3

//用正向兑换函数 f 套反向求解
#include<bits/stdc++.h>
using namespace std;
const int K=3;

int f(int a)
{
    int res=0;
    while(a>=K)
    {
        res+=a/K;
        a=a%K+a/K;
    }
    return res;
}

int main()
{
    int N;cin>>N;
    cout<<N-f(N-N/K);
    return 0;
}

( cout<<N-f(N-N/K); 看着好像牛顿法啊)