【每日一题】Problem 538B. Quasi Binary
1.【每日一题】Problem 363B. Fence2.【每日一题】Problem 331C1. The Great Julya Calendar3.【每日一题】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 Exercise
23.【每日一题】Problem 538B. Quasi Binary
解决思路
最简单的思路就是贪心了,每次生成不超过目标值的
#include <bits/stdc++.h>
int quasibinary(int max)
{
int res = 0;
int p = 0;
while (max > 0) {
if (max % 10 > 0) {
res += int(pow(10, p));
}
max /= 10;
++p;
}
return res;
}
int main()
{
int n; std::cin >> n;
std::vector<int> res;
while (n > 0) {
int target = quasibinary(n);
n -= target;
res.push_back(target);
}
std::cout << res.size() << std::endl;
for (auto &v : res) {
std::cout << v << " ";
}
std::cout << "\n";
return 0;
}
其他解
可以考虑使用 dp,待补充
完全背包
本文来自博客园,作者:HelloEricy,转载请注明原文链接:https://www.cnblogs.com/HelloEricy/p/17567045.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步