设为首页 加入收藏

TOP

CF 538B(Quasi Binary-贪心)
2015-11-21 01:03:44 来源: 作者: 【 】 浏览:1
Tags:538B Quasi Binary- 贪心

?

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.

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 test(s) input
9
output
9
1 1 1 1 1 1 1 1 1 
input
32
output
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<
            
             

?

?

?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇CF 538D(Weird Chess-反过来算) 下一篇算法学习 - 01背包问题(动态规划..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: