[CF538B] Quasi Binary
Description
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer nn . Represent it as a sum of minimum number of quasibinary numbers.
Input
The first line contains a single integer
Output
In the first line print a single integer
In the second line print
Sample Input1
9
Sample Output1
9
1 1 1 1 1 1 1 1 1
Sample Input2
32
Sample Output2
3
10 11 11
题解
题意(来自洛谷)
题目描述:给出一个数n,你需要将n写成若干个数的和,其中每个数的十进制表示中仅包含0和1。问最少需要多少个数
输入格式:一行 一个数 n()
输出格式:最少的数的个数,并给出一种方案。
很显然,最少需要多少个数取决于
分别为
这样我们可以将每一位分别处理,这里我是从个位开始处理的
其实这也可以这样理解,
#include<iostream>
#include<cstdio>
using namespace std;
int Ans,num[100];//其实这里定义10就够了,因为最多9个数就一定可以构成n
int main()
{
int n,Res;
scanf("%d",&n);
for(int bit=1;bit<=n;bit*=10)
{
Res=(n/bit)%10;//每一位的数值
Ans=max(Ans,Res);
for(int i=1;i<=Res;++i) num[i]+=bit;
}
printf("%d\n",Ans);
for(;Ans;--Ans) printf("%d ",num[Ans]);//倒序输出,从小到大
putchar('\n');
return 0;
}
本文作者:OItby @ https://www.cnblogs.com/hihocoder/
未经允许,请勿转载。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· DeepSeek 解答了困扰我五年的技术问题。时代确实变了!
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· 趁着过年的时候手搓了一个低代码框架
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!