跳到正文

题解

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

xyx012约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年6月4日
收录
2026年8月27日
更新
2026年11月9日
篇幅
约 1 分钟
题目
B3629

版本

  1. v1当前

题目传送门

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

C++
//用正向兑换函数 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); 看着好像牛顿法啊)

原文