【每日一题】Problem 331C1. The Great Julya Calendar
1.【每日一题】Problem 363B. Fence
2.【每日一题】Problem 331C1. The Great Julya Calendar
3.【每日一题】Problem 327A - Flipping Game4.【每日一题】Problem 313B - Ilya and Queries5.【每日一题】Problem 1832B - Maximum Sum6.【每日一题】Problem 44E. Anfisa the Monkey7.【每日一题】Problem 120F. Spiders8.【每日一题】Problem 174B. File List9.【每日一题】Problem 180C. Letter10.【每日一题】Problem 189A. Cut Ribbon11.【每日一题】Problem 234C. Weather12.【每日一题】Problem 253B. Physics Practical13.【每日一题】Problem 443B. Kuriyama Mirai's Stones14.【每日一题】Problem 416B. Art Union15.【每日一题】Problem 489B. BerSU Ball16.【每日一题】Problem 476B. Dreamoon and WiFi17.【每日一题】Problem 489C. Given Length and Sum of Digits...18.【每日一题】Problem 505B. Mr. Kitayuta's Colorful Graph19.【每日一题】Problem 289B. Polo the Penguin and Matrix20.【每日一题】Problem 414B. Mashmokh and ACM21.【每日一题】Problem 522A. Reposts22.【每日一题】Problem 1195C. Basketball Exercise23.【每日一题】Problem 538B. Quasi Binary解决思路
寻求减到 0 所需的最小次数,即
当存在一个 x 使得 (n - x)% 10 = 0 时,那么(n - x)到下一次个位为 0 时至少需要两次,即该过程至少需要 3 次
如果存在一个 x' > x,那么上述过程可以简化到至少需要 2 次
一般情况下,当 n 中的前面一段(百位之前)的数比较小时,每次减法运算都会使得个位出现较大的数,此时 x' 大小不影响次数
对于 n(个位数为 0) -> 0 可以看作 n(个位数为 0) -> n'(个位数为 0) -> 0,因此每次减去 max(x') 所需次数 ≤ 任意的 x'所需次数
#include <bits/stdc++.h>
int getMaxDigit(long long n) {
long long d = 0;
while (n > 0) {
d = std::max(d, n % 10);
n /= 10;
}
return int(d);
}
int main() {
long long n; std::cin >> n;
int count = 0;
while (n > 0) {
int d = getMaxDigit(n);
n -= d;
++count;
}
std::cout << count << std::endl;
return 0;
}
缺陷
该做法无法通过 C2
本文来自博客园,作者:HelloEricy,转载请注明原文链接:https://www.cnblogs.com/HelloEricy/p/17472155.html
合集:
每日一题
分类:
每日一题 / 动态规划
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步