Codeforces 538 B. Quasi Binary
2 seconds
256 megabytes
standard input
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.
The first line contains a single integer n (1 ≤ n ≤ 106).
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.
9
9
1 1 1 1 1 1 1 1 1
32
3
10 11 11
题意就是把一个数用0,1组成的数来代替,让这些数的和为这个数。
代码:
#include<bits/stdc++.h>
using namespace std;
int a,b,i,m,t=1,g[10];
int main(){
cin>>a;
while(a){
b=a%10;
for(i=9;i>9-b;i--)
g[i]+=t;
if(b>m) m=b;
t*=10;
a/=10;
}
cout<<m<<endl;
for(i=0;i<10;i++){
if(g[i])
cout<<g[i]<<" ";
}
return 0;
}
Codeforces 538 B. Quasi Binary的更多相关文章
- Codeforces Round #300 Quasi Binary(DP)
Quasi Binary time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #300 B. Quasi Binary 水题
B. Quasi Binary Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/probl ...
- Codeforces 538 F. A Heap of Heaps
\(>Codeforces \space 538 F. A Heap of Heaps<\) 题目大意 :给出 \(n\) 个点,编号为 \(1 - n\) ,每个点有点权,将这些点构建成 ...
- B. Quasi Binary
开启博客园 记录codeforces程序 这个题目很简单 一个数能被最少的只包含0 ,1的数字和 如:9 = 1+1+1+1+1+1+1+1+1 10 =10 12 =11+ 1 求得是最少个数的整数 ...
- Codeforces 551D GukiZ and Binary Operations(矩阵快速幂)
Problem D. GukiZ and Binary Operations Solution 一位一位考虑,就是求一个二进制序列有连续的1的种类数和没有连续的1的种类数. 没有连续的1的二进制序列的 ...
- 【Codeforces Round 1114】Codeforces #538 (Div. 2)
Codeforces Round 1114 这场比赛做了\(A\).\(C\).\(D\).\(E\),排名\(134\). \(B\)题做了很长时间,好不容易最后一分钟\(Pretest\ Pass ...
- Codeforces 538 A. Cutting Banner-substr()函数字符串拼接
A. Cutting Banner time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces 1237E Perfect Balanced Binary Search Tree
题目链接 Observations 含有 $n$ 个点且 key(以下也称 key 为「权值」)是 1 到 $n$ 的 BST 具有下列性质: 若 $k$ 是一个非根叶子且是个左儿子,则 $k$ 的父 ...
- codeforces 400E. Inna and Binary Logic 线段树
题目链接 给出n个数, 定义a[1][i]为这初始的n个数, 然后a[i][j] = a[i-1][j]&a[i-1][j-1], 这样就可以得到一个三角形一共n*(n-1)/2个数. 给出一 ...
随机推荐
- 【其他】Windows 系统安装IIS 打开页面出现空白解决方案
部署IIS过程中遇到了一个奇怪的问题,就是怎么设置打开的页面都是一篇空白,IIS也没有任何报错,翻遍互联网好不容易找到了解决方法,今天就教给大家,希望大家不要走弯路.此方法Windows xp.7.8 ...
- P1268 树的重量
题目描述 树可以用来表示物种之间的进化关系.一棵“进化树”是一个带边权的树,其叶节点表示一个物种,两个叶节点之间的距离表示两个物种的差异.现在,一个重要的问题是,根据物种之间的距离,重构相应的“进化树 ...
- P1531 I Hate It
题目背景 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.这让很多学生很反感. 题目描述 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的 ...
- 东北育才冲刺noip(day9)
这十天来呢,感觉自己进步很大,(虽然被碾压的很惨),看到了自己以前完全没见过,也没想过的算法,打开新世界的大门. 同时呢,也感觉自己太弱了,于是就注册了这个博客. 为了促进进步,在这里立下flag,我 ...
- oracle的sql语句训练
--查询工资最高的人的名字select ename ,sal from emp where sal=(select max(sal) from emp );--求出员工的工资在所有人的平均工资之上的人 ...
- bzoj 1517 [POI2006]Met 贪心
[POI2006]Met Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 203 Solved: 108[Submit][Status][Discus ...
- [04] css 选择器
1.元素选择器 常见的html标签元素 h1 { color: red; } body { background: red; } 2.分组选择器 例如body和h2标签的字体颜色都是red,使用逗号将 ...
- 面向对象的tab选项卡实现
利用最基础的面向对象的思想,实现tab选项卡效果: 效果截图:
- jsp分页完善版
明天要考网络工程师了,而且这两天校运会,把那个分页的完善了下,明天考试,祈祷吧,我根本都没看书啊,所以只能去长见识了.100大洋啊,下个学期我想考考证了,不然以后出去麻烦了.呵呵,不多说还是说说自己对 ...
- 动态规划:DAG-嵌套矩形
据说DAG是动态规划的基础,想一想还真的是这样的,动态规划的所有状态和转移都可以归约成DAG DAG有两个典型模型,一个是嵌套矩形问题一个是硬币问题,这里仅介绍一个嵌套矩形问题 等二轮复习的时候再补上 ...