Codeforces Round #300 B

Source: Internet
Author: User

B. Quasi Binary

A number is called quasibinary if it decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011-are quasibinary and Numbers 2,.

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 Q Uasibinary numbers.

The second line print K numbers-the elements of the sum. All these numbers should is quasibinary according to the definition above, their sum should equal n. Do not has the to print the leading zeroes in the numbers. The order of numbers doesn ' t matter. If There is multiple possible representations, you is 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

Good question, very good question ~
Test instructions is to select the smallest number of numbers in a number of only 01 to make up N. and output these numbers.
Conventional ideas are easy to see, not more than 1000000 of the 01 number is 64, a table is not able to live it? But the question is not whether it can constitute n, but rather the number of components that require the least amount of output. Looks like a backpack, but not very good back. Because you have to record the best intermediate distance.
But the problem is a good idea is to use 01, put n a good look, each bit as a number, then the largest number is the result. Knock good each one to take a 1, not enough is 0, then the composition of this res number is not exactly what is required. OK, the answer is Jiangzi.
In fact, I think the problem-solving report is best not attached. The result of the uniform accompanying code is that everyone is lazy.
But I'm still attached. (^o^)/~ haha

#include <functional>#include <cstdio>#include <cstring>#include <string>#include <cctype>#include <cstdlib>#include <ctime>#include <climits>#include <cmath>#include <iostream>#include <string>#include <vector>#include <set>#include <map>#include <list>#include <queue>#include <stack>#include <deque>#include <algorithm>#define Read Freopen ("Q.in", "R", stdin)#define Write Freopen ("Q.out", "w", stdout)#define LL Long Long#define MAXN 1000005#define MOD 9999999999using namespace STD;inta[Ten];intCntvoidGetintN) {cnt=0; while(n) {a[cnt++]=n%Ten; N/=Ten; }}intMain () {intN while(~scanf("%d", &n)) {intI,j; Get (n);intres=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; }}

Codeforces Round #300 B

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.