CF538B Quasi Binary 题解

  • 题目
    • 链接
    • 字面描述
      • 题面翻译
      • 题目描述
      • 输入格式
      • 输出格式
      • 样例 #1
        • 样例输入 #1
        • 样例输出 #1
      • 样例 #2
        • 样例输入 #2
        • 样例输出 #2
  • 思路
  • 代码实现

题目

链接

https://www.luogu.com.cn/problem/CF538B

字面描述

题面翻译

题目描述

给出一个数n,你需要将n写成若干个数的和,其中每个数的十进制表示中仅包含0和1。

问最少需要多少个数

输入输出格式

输入格式:

一行 一个数 n(1≤n≤10^6)

输出格式:

最少的数的个数,并给出一种方案。

题目描述

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.

输入格式

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

输出格式

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.

样例 #1

样例输入 #1

9

样例输出 #1

9
1 1 1 1 1 1 1 1 1

样例 #2

样例输入 #2

32

样例输出 #2

3
10 11 11

思路

此问题说将 n n n分解为各个数位只能是 1 1 1或 0 0 0的数的和。
转化一下(翻译成人话):至多少分解成 m a x ( ( n / 1 0 i ) m o d ( 10 ) ) max((n/10^i)mod(10)) max((n/10i)mod(10))(各个数位上数的最大值,最多为 9 9 9),再将这些平均分配落实到每一个数中即可。

例如 114514 114514 114514
根据上述,至少分解成 5 5 5个数,分别是 111111 111111 111111, 1101 1101 1101, 1101 1101 1101, 1101 1101 1101, 100 100 100

代码实现

#include<bits/stdc++.h>
using namespace std;const int maxn=100+10;
int n,cnt;
int ans[maxn];
int main(){scanf("%d",&n);for(int i=1;i<=n;i*=10){int x=(n/i)%10;cnt=max(cnt,x);for(int j=1;j<=x;j++)ans[j]+=i;}printf("%d\n",cnt);for(int i=1;i<=cnt;i++)printf("%d ",ans[i]);return 0;
}

CF538B Quasi Binary 题解相关推荐

  1. [CF538B]Quasi Binary

    题目大意 懒得写 做法 这样的数只有2^6个. 因此暴力DP #include<cstdio> #include<algorithm> #include<cstring& ...

  2. CF538B Quasi Binary

    因为输出是每一位最大为1,所以最少就要输出n个,n为原数K:abcd-z中最大的那一个数. Eg: 123456 n=6 100009 n=9 309079 n=9 先用数组存每一位,然后哪位用完了就 ...

  3. 538B. Quasi Binary

    B. Quasi Binary:题目 这题目建议挪到1000分,它不配1400 #include <bits/stdc++.h> using namespace std; #define ...

  4. 洛谷(小鱼的数字游戏、进制转换、Cableway、Quasi Binary)

    小鱼的数字游戏: 代码: #include<iostream> #include<cstring> #include<algorithm> using namesp ...

  5. B. Quasi Binary

    开启博客园 记录codeforces程序 这个题目很简单 一个数能被最少的只包含0 ,1的数字和 如:9 = 1+1+1+1+1+1+1+1+1 10 =10 12 =11+ 1 求得是最少个数的整数 ...

  6. ios 获取相册第一个视频_历史上第一个视频游戏

    ios 获取相册第一个视频 重点 (Top highlight) Looking closely at the oscilloscope, you what function the picture ...

  7. 【cf】Codeforces 题解等汇总

    [cf]Codeforces Round #774 (Div. 2) 前4题 [cf]Codeforces Round #774 (Div. 2) 前4题_legend_yst的博客-CSDN博客 [ ...

  8. 2017寒假练习题解 第四周 2.6-2.12

    2.6 Problem A Quasi Binary 题意:给出 n ,输出n至少由k个只含 01的数组成 简析:按照 n 的位数如果相应的一位不是0的话,就填 1 ,再减去,直到减到 n 为0 1 ...

  9. 2021算法竞赛入门班第一节课枚举贪心习题

    文章目录 1.明明的随机数 2.回文日期 3.校门外的树 4.数学考试 5.Subsequence 6.字符串 7.丢手绢 8.拼数 9.纪念品分组 10.国王的游戏 11.铺地毯 12.「土」巨石滚 ...

最新文章

  1. FIS前端集成解决方案
  2. VUE config/index.js文件配置
  3. VS配合VSS时,编译报错:未能向文件“....csproj.FileListAbsolute.txt”写入命令行,对路径的访问被拒绝。...
  4. yolo算法_不到2MB,超轻YOLO算法!准确率接近YOLOv3,速度快上45%
  5. Exchange 2013CU17和office 365混合部署-设置属性筛选(三)
  6. GDI+中发生一般性错误的解决办法(转)
  7. 软件测试用例最简单最常见的模板和案例(QQ登陆,手机号,126邮箱)
  8. KGB知识图谱成功落地金融行业
  9. 使用PowerCli来创建自定义ESXi ISO镜像
  10. Bezier曲线原理及实现代码(c++)
  11. 装修到底要不要请设计师?
  12. 亚马逊SP-API申请,亚马逊SP-API注册,亚马逊开发者申请,PII申请怎么做?SP-API是什么?
  13. NOSQL原理,基础用法,NOSQL入门
  14. 血氧仪方案功能及使用方法介绍
  15. CPU的计算机能力和AVX512指令集
  16. matlab中求最大因数,matlab最大公约数 三种算法
  17. idea中搭建基于maven的ssm整合框架
  18. linux桌面环境日志,小白的Linux桌面环境的配置手记
  19. 技巧】利用chromg浏览器自动翻译外文网页的设置方法---电脑版
  20. 各内网客户端实现P2P方案

热门文章

  1. Reeds-Shepp曲线和Dubins曲线相关资料汇总
  2. 使用 typedef 定义函数指针,更优雅的使用函数指针
  3. 如何自己搭建虚拟主机
  4. 舆论产生相关话题怎么查找搜索的解决方法参考
  5. python 因果推断_[Python]因果检验工具
  6. ubuntu20.04开展华为手机adb安装及调试app运行出错闪退的步骤
  7. 2021年黄冈副高考试成绩查询,2021年黄冈中考成绩排名查询,黄冈中考个人成绩排名查询...
  8. app研发录第一章笔记
  9. Jabber 协议 概述(转载)
  10. 2019字节跳动笔试题