首页 > 其他 > 详细

Codeforces Round #300 - Quasi Binary(贪心)

时间:2015-05-01 17:26:55      阅读:228      评论:0      收藏:0      [点我收藏+]

Quasi Binary
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

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

Input
9
Output
9
1 1 1 1 1 1 1 1 1 
Input
32
Output
3
10 11 11 

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const double pi= acos(-1.0);
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
char str[10];
int main()
{
    int max_cnt;
    int first;
    while(~scanf("%s",str)){
        int len=strlen(str);
        max_cnt=0;
        for(int i=0;i<len;i++){
            max_cnt=max(max_cnt,str[i]-'0');
        }
        printf("%d\n",max_cnt);
        for(int i=0;i<max_cnt;i++){
            first=0;
            for(int j=0;j<len;j++){
                if(!first){
                    if(str[j]!='0'){
                        printf("1");
                        str[j]--;
                        first=1;
                    }
                }
                else{
                    if(str[j]!='0'){
                        printf("1");
                        str[j]--;
                    }
                    else{
                        printf("0");
                    }
                }
            }
            printf(" ");
        }
        puts("");
    }
    return 0;
}


Codeforces Round #300 - Quasi Binary(贪心)

原文:http://blog.csdn.net/u013486414/article/details/45420063

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!