B. Quasi Binary time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output
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.
InputThe first line contains a single integer n (1?≤?n?≤?106).
OutputIn 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) input9output
9 1 1 1 1 1 1 1 1 1input
32output
3 10 11 11
貪心,每個答案的數盡量取1
#include#include #include #include #include #include #include #include #include using namespace std; #define For(i,n) for(int i=1;i<=n;i++) #define Fork(i,k,n) for(int i=k;i<=n;i++) #define Rep(i,n) for(int i=0;i =0;i--) #define Forp(x) for(int p=pre[x];p;p=next[p]) #define Lson (x<<1) #define Rson ((x<<1)+1) #define MEM(a) memset(a,0,sizeof(a)); #define MEMI(a) memset(a,127,sizeof(a)); #define MEMi(a) memset(a,128,sizeof(a)); #define INF (2139062143) #define F (100000007) #define MAXN (1000000+10) long long mul(long long a,long long b){return (a*b)%F;} long long add(long long a,long long b){return (a+b)%F;} long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;} typedef long long ll; int n; int a[MAXN],siz=0; int c[MAXN],d[MAXN]; int main() { // freopen("b.in","r",stdin); // freopen(".out","w",stdout); cin>>n; d[1]=1; Fork(i,2,8) d[i]=d[i-1]*10; int siz=0; while(n) { a[++siz]=n%10; n/=10; } int k=0; MEM(c) For(i,siz) { k=max(k,a[i]); For(j,a[i]) c[j]+=d[i]; } cout<