zoukankan      html  css  js  c++  java
  • [CF538B] Quasi Binary

    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 nn . Represent it as a sum of minimum number of quasibinary numbers.

    Input

    The first line contains a single integer (n) ((1<=n<=10^{6})).

    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 Input1

    9
    

    Sample Output1

    9
    1 1 1 1 1 1 1 1 1 
    

    Sample Input2

    32
    

    Sample Output2

    3
    10 11 11 
    

    题解

    题意(来自洛谷)

    题目描述:给出一个数n,你需要将n写成若干个数的和,其中每个数的十进制表示中仅包含0和1。问最少需要多少个数
    输入格式:一行 一个数 n((1≤n≤10^6)
    输出格式:最少的数的个数,并给出一种方案。

    很显然,最少需要多少个数取决于(max)(一个数的每一位),下面举个例子:

    (12321),组成这个数的最大的数字是(3),因此最少(3)个满足条件的数就可以构成(12321)

    分别为(11111)(1110)(100)

    这样我们可以将每一位分别处理,这里我是从个位开始处理的

    其实这也可以这样理解,(12321)是由(2321)转移过来的,同理,…

    #include<iostream>
    #include<cstdio>
    using namespace std;
    
    int Ans,num[100];//其实这里定义10就够了,因为最多9个数就一定可以构成n
    
    int main()
    {
    	int n,Res;
    	scanf("%d",&n);
    	for(int bit=1;bit<=n;bit*=10)
    	{
    		Res=(n/bit)%10;//每一位的数值
    		Ans=max(Ans,Res);
    		for(int i=1;i<=Res;++i) num[i]+=bit;
    	}
    	printf("%d
    ",Ans);
    	for(;Ans;--Ans) printf("%d ",num[Ans]);//倒序输出,从小到大
    	putchar('
    ');
    	return 0;
    }
    

  • 相关阅读:
    select 标签的数据绑定
    JQ选择器-选择符合条件的元素,获取对应关系元素
    Velocity中判断表达式是不是为空
    重要的serialVersionUID
    编译nginx的时候报错 需要安装PCRE
    Mac 允许安装任何来源的app
    Charles
    Excel_日期和时间函数、EDATE、EOMONTH
    项目9: 成绩中国式排名(难度:中等)
    Mysql:IFNULL的使用说明
  • 原文地址:https://www.cnblogs.com/hihocoder/p/12587269.html
Copyright © 2011-2022 走看看