B. Quasi Binary
开启博客园
记录codeforces程序
这个题目很简单
一个数能被最少的只包含0 ,1的数字和
如:9 = 1+1+1+1+1+1+1+1+1
10 =10
12 =11+ 1
求得是最少个数的整数和
对于任意的一个数,小于等于这个数的最大的只有0 1序列组成的数,满足:原数位置是0,这个数位置是0,原数位置非0,这个数位置是1.
根据这个规则,就可以求出所有的数。
输入:
n
输出:
k
k个数
Java程序如下:
import java.util.Scanner;
public class B538 {
public static void run(){
Scanner in = new Scanner(System.in);
String digit = in.next();
int count = 0;
String[] array = new String[1000];
while(Integer.valueOf(digit)!=0){
String str = "";
for(int i = 0;i<digit.length();i++)
if(digit.charAt(i)!='0')
str = str+"1";
else str = str + "0" ;
digit = (Integer.valueOf(digit) - Integer.valueOf(str))+"";
array[count] = str;
count++;
}
System.out.println(count);
for(int i=0;i<count;i++)
System.out.print(array[i]+" ");
}
public static void main(String[] args){
run();
}
}
Python程序:
n = int(raw_input())
9
res=[]
while n>0:
s=str(n)
now = 0
for i in xrange(0,len(s)):
if int(s[i])>0:
now+ 10**(len(s)-i-1)
res.append(now)
n-=now
print len(res)
for i in res:
print i,
B. Quasi Binary的更多相关文章
- Codeforces Round #300 B. Quasi Binary 水题
B. Quasi Binary Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/probl ...
- Codeforces Round #300 Quasi Binary(DP)
Quasi Binary time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces 538 B. Quasi Binary
B. Quasi Binary time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- CF538B Quasi Binary 思维题
题目描述 给出一个数 \(n\),你需要将 \(n\) 写成若干个数的和,其中每个数的十进制表示中仅包含\(0\)和\(1\). 问最少需要多少个数 输入输出格式 输入格式: 一行 一个数 \(n(1 ...
- Codeforces Round #300(A.【字符串,多方法】,B.【思维题】,C.【贪心,数学】)
A. Cutting Banner time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- Codeforces Round #300 解题报告
呜呜周日的时候手感一直很好 代码一般都是一遍过编译一遍过样例 做CF的时候前三题也都是一遍过Pretest没想着去检查... 期间姐姐提醒说有Announcement也自信不去看 呜呜然后就FST了 ...
- [数据结构]——二叉树(Binary Tree)、二叉搜索树(Binary Search Tree)及其衍生算法
二叉树(Binary Tree)是最简单的树形数据结构,然而却十分精妙.其衍生出各种算法,以致于占据了数据结构的半壁江山.STL中大名顶顶的关联容器--集合(set).映射(map)便是使用二叉树实现 ...
- ILJMALL project过程中遇到Fragment嵌套问题:IllegalArgumentException: Binary XML file line #23: Duplicate id
出现场景:当点击"分类"再返回"首页"时,发生error退出 BUG描述:Caused by: java.lang.IllegalArgumentExcep ...
- Leetcode 笔记 110 - Balanced Binary Tree
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...
随机推荐
- ios开发--常用宏定义(部分转)
1.release时,屏蔽log #if defined (DEBUG) && DEBUG == 1 #else #define NSLog(...) {}; #endif #if d ...
- Java中的访问权限
Java中有四种访问权限,从大到小依次是:public –> protected –> default(friendly) –> private. 简单说明下: public 作用域 ...
- Mysql的相关命令
1.登录服务器 mysql -h host -u user -p mysql -h host -u user -p 数据库 2.使用SHOW语句找出服务器上当前存在什么数据库:mysql> SH ...
- 1.1 MySQL 逻辑架构
- JNA开发中的问题积累
[Qboy原创] 2013年12月28日 在开发一个项目过程中需要调用第三方的C的dll.由于是第一次在项目中使用JNA,很多都安装开发文档来做,但是出现了很多的问题. 由于很多接口还没调完,还不知道 ...
- XAML中ContentControl,ItemsControl,DataTemplate之间的联系和区别
接触XAML很久了,但一直没有深入学习.今天学习了如标题所示的内容,所以来和大家分享一下,或者准确的说是自我回顾一遍. 在XAML中,有两类我们常见的控件,分别是ContentControl和Item ...
- B-tree/B+tree/B*tree [转]
(原文出处:http://blog.csdn.net/hbhhww/article/details/8206846) B~树 1.前言: 动态查找树主要有:二叉查找树(Binary Search Tr ...
- Ubuntu14.04搭建LAMP环境
安装Apache2 sudo apt-get install apache2 ...
- VMM学习-vmm_log
功能类似verilog里的$display函数,在vmm里做了强化,可以在仿真过程中看到整个平台的运行信息,用来调试仿真平台. 函数原型在vmm.sv里(class vmm_log;),其构造函数为e ...
- Django RequestContext用法
模版中的变量由context中的值来替换,如果在多个页面模版中含有相同的变量,比如:每个页面都需要{{user}},笨办法就是在每个页面的请求视图中都把user放到context中. from d ...