Codeforces Round #300 - Quasi Binary(贪心)

Quasi Binary

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

Submit Status

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;
}
时间: 2024-10-18 10:09:53

Codeforces Round #300 - Quasi Binary(贪心)的相关文章

Codeforces Round #300——C贪心——Tourist&#39;s Notes

Description A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer hi. The tourist pick smooth enough route for his hike, me

贪心 Codeforces Round #300 A Cutting Banner

题目传送门 1 /* 2 贪心水题:首先,最少的个数为n最大的一位数字mx,因为需要用1累加得到mx, 3 接下来mx次循环,若是0,输出0:若是1,输出1,s[j]--: 4 注意:之前的0的要忽略 5 */ 6 #include <cstdio> 7 #include <iostream> 8 #include <cstring> 9 #include <string> 10 #include <algorithm> 11 #include

Codeforces Round #300 (A,B,C,D)

题目传送:Codeforces Round #300 A. Cutting Banner 思路:一看题就会错意了,然后一顿猛敲,果不其然的被hack了,然后才发现只需要剪中间那一段就可以了,然后又傻逼得少写一个等号,还是被hack了,心累啊 AC代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> #in

Codeforces Round #300-Tourist&#39;s Notes(贪心)

Tourist's Notes Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level

水题 Codeforces Round #300 A Cutting Banner

题目传送门 1 /* 2 水题:一开始看错题意,以为是任意切割,DFS来做:结果只是在中间切出一段来 3 判断是否余下的是 "CODEFORCES" :) 4 */ 5 #include <cstdio> 6 #include <iostream> 7 #include <cstring> 8 #include <string> 9 #include <algorithm> 10 #include <cmath>

Codeforces Round #300

A. Cutting Banner 关键字:[读题][字符串][枚举] 坑点:能不能只减去某一段字符串把剩下的按原来的顺序连起来组成"CODEFORCES",而减下一段"CODEFORCES"是不行的 e.g. "CODEFAAAAORCES"是可行的         而 "AACODEFORCESAA"是不可行的 B. Quasi Binary 题意:给出一个数n,求最少用几个形如"1010"这样只包含'

Codeforces Round #300 B

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 s

Codeforces Round #300 E - Demiurges Play Again

E - Demiurges Play Again 感觉这种类型的dp以前没遇到过... 不是很好想.. dp[u] 表示的是以u为子树进行游戏得到的值是第几大的. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PII pair<int, int> #define y1 skldjfskldjg #define y

Codeforces Round #598 (Div. 3) D - Binary String Minimizing

原文链接:https://www.cnblogs.com/xwl3109377858/p/11797618.html Codeforces Round #598 (Div. 3) D - Binary String Minimizing You are given a binary string of length n (i. e. a string consisting of n characters '0' and '1'). In one move you can swap two adj