[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 n (1<=n<=106).

Output

In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.

In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n . Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.

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(1n106
输出格式:最少的数的个数,并给出一种方案。

很显然,最少需要多少个数取决于max(一个数的每一位),下面举个例子:

12321,组成这个数的最大的数字是3,因此最少3个满足条件的数就可以构成12321

分别为111111110100

这样我们可以将每一位分别处理,这里我是从个位开始处理的

其实这也可以这样理解,12321是由2321转移过来的,同理,…

#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;
}

posted @   OItby  阅读(328)  评论(0编辑  收藏  举报
编辑推荐:
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
阅读排行:
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· DeepSeek 解答了困扰我五年的技术问题。时代确实变了!
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· 趁着过年的时候手搓了一个低代码框架
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!
点击右上角即可分享
微信分享提示