u010582475的专栏

B. Quasi Binary

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 n. 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 test(s) Input

9

Output

9 1 1 1 1 1 1 1 1 1

Input

32

Output

3 10 11 11

好题,很好的题~ 题意就是在只有01组成的数字中选取最小数量的数组成n。并且输出这些数。 常规的思路很容易看到,,不大于1000000的01数才64个,打个表是不是就能过呢?但是问题关键不是问是否能构成n,而是要求输出最少的构成n的数。看似像个背包,但是又不太好背。。因为还要记录最优的中间路程。 但是这个题一个很好地思路就是利用01,把n好好看一下,每一位当做一个数,那么其中最大的数就是结果。敲好把每一位都取一个1,不够的就是0,那么组成的这res个数不刚好就是符合要求的么。OK,答案就是酱紫的。 其实,我觉得解题报告最好不要附带吗。千篇一律的附代码造成的结果就是大家的懒惰。 可是我还是附了。。(^o^)/~ 哈哈

;int a[10];int cnt;void get(int n){cnt=0;while(n){a[cnt++]=n%10;n/=10;}}int main(){ int n; while(~scanf(“%d”,&n)) {int i,j;get(n);int res=0;for(i=0;i<cnt;i++){res=max(res,a[i]);}cout<<res<<endl;for(j=0;j<res;j++){i=cnt-1;while(a[i]<=0)i–;for(;i>=0;i–){if(a[i]>0)cout<<“1”;else cout<<“0″;if(a[i])a[i]–;}cout<<” “;}cout<<endl;}}

如果说,罗马是一座厚重和凝固的堡垒,

u010582475的专栏

相关文章:

你感兴趣的文章:

标签云: