Codeforces Round #300 B. Quasi Binary 水题

B. Quasi Binary

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/538/problem/B

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 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 Input

9

Sample Output

9
1 1 1 1 1 1 1 1 1

HINT

题意

 给你一个数n,然后让你找 一些01组成的数,让这些数的和为n,让找最少的数,并且输出这些数

题解:

啊,对于每一位,由于最多减1,所以最少一定是每一位的最大值,比如213,则必须3次,才能把个位变成0

有这个想法之后,就不难做了,我们直接减1就了,当为0 的时候,就不减了

注意前导0的问题

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[20];
//const int inf=0x7fffffff;   //нчоч╢С
const int inf=0x3f3f3f3f;
/*

inline void P(int x)
{
    Num=0;if(!x){putchar('0');puts("");return;}
    while(x>0)CH[++Num]=x%10,x/=10;
    while(Num)putchar(CH[Num--]+48);
    puts("");
}
*/
inline ll read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline void P(int x)
{
    Num=0;if(!x){putchar('0');puts("");return;}
    while(x>0)CH[++Num]=x%10,x/=10;
    while(Num)putchar(CH[Num--]+48);
    puts("");
}
//**************************************************************************************


int main()
{
    string s;
    cin>>s;
    int len=0;
    for(int i=0;i<s.size();i++)
        len=max(len,s[i]-'0');
    cout<<len<<endl;
    for(int i=0;i<len;i++)
    {
        int flag=0;
        for(int j=0;j<s.size();j++)
        {
            if(!flag)
            {
                if(s[j]=='0')
                    continue;
                else
                {
                    cout<<"1";
                    s[j]--;
                    flag=1;
                }
            }
            else
            {
                if(s[j]=='0')
                    cout<<"0";
                else
                {
                    cout<<"1";
                    s[j]--;
                }
            }

        }
        cout<<" ";
    }
}
原文地址:https://www.cnblogs.com/qscqesze/p/4458883.html