程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> CF 538B(Quasi Binary-貪心)

CF 538B(Quasi Binary-貪心)

編輯:C++入門知識

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

 

 

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved