跳到正文

个人记录

NOIP2025模拟赛23

zhangzhiqi2026约 3 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 3 分钟

版本

  1. v1当前
T1T2T3T4
普及+/提高\color{#52C41A} 普及+/提高提高+/省选−\color{#3498DB} 提高+/省选-普及+/提高\color{#52C41A} 普及+/提高省选/NOI−\color{#9D3DCF} 省选/NOI-

参赛网址:https://oj.33dai.cn/d/TYOI/contest/689d2670c5d9c2f14c2250d7

T1 粉丝[2022NOIP模拟赛T1]

题目传送门

题目难度:普及+/提高\color{#52C41A} 普及+/提高

算法标签:数据结构,并查集,BFS

思路

测试点编号p≤p \leqt≤t \leqk≤k \leq时限
1∼71 \sim 710510^510310^3100ms100ms
8∼108 \sim 1010610^6
11∼3011 \sim 30101810^{18}kk10310^32000ms2000ms
3131略略略2000ms2000ms

赛后添加了一组 hack(31) 数据

首先考虑测试点 1∼101 \sim 10:

我们可以轻松考虑到动态规划

AC Code

C++
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int maxn=1e6+5;
int t,k,p;
int f[maxn];
deque<int> Q;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>t>>k>>p;
    if (k==1)    cout<<(p-1+t-1)/t+1;
    else if (p<=maxn){
        memset(f,0x3f,sizeof(f));
        f[1]=1;
        Q.push_back(1);
        for (int i=2;i<=p;i++){
            f[i]=min(f[i],f[Q.front()]+1);
            if (i%k==0) f[i]=min(f[i],f[i/k]+1);
            while (Q.size()>0&&f[i]<=f[Q.back()])  Q.pop_back();
            Q.push_back(i);
            while (Q.size()>0&&Q.front()<=i-t)    Q.pop_front();
        }
        cout<<f[p];
    }
    else {
        int ans=0;
        while (p>=k){
            int d=(p%k+t-1)/t+1;
            ans+=d;
            p=(p-p%k)/k;
        }
        ans+=(p-1+t-1)/t+1;
        cout<<ans;
    }
    return 0;
}
原文