跳到正文

题解

题解:P14027 【MX-X20-T1】「FAOI-R7」加训加训

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

文章信息

发布
2025年9月13日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 1 分钟
题目
P14027

版本

  1. v2当前
  2. v1

题目大意

题目传送门

题目分析

显然,当 aa 的初值为 00 或 11 时,普通训练一定比加训加训好。因为当 a=0a = 0 时,怎么乘都是 00。当 a=1a = 1 时,如果加训,则 aa 变为 kk,如果普通训练,则 aa 变为 k+1k + 1,显然后者更优。 剩下的直接乘就完了。

注意

一定要特判 k=1k = 1 的情况,不然会死循环 TLE。

代码实现

C++
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

#define int long long

#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int a,b,k;// 如题意所述
int ans=0;

signed main()
{
	fst
	cin>>a>>b>>k;
	if(k==1){// 一定要特判
		cout<<b-a;
		return 0;
	}
	while(a<b){
		if(a==0||a==1){
			ans++;
			a+=k;
			continue;
		}
		ans++;
		a*=k;
	}
	cout<<ans;
	return 0;
}
原文