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 ...
随机推荐
- @property @synthesize的含义以及误区。
@property的作用是定义属性,声明getter,setter方法.(注意:属性不是变量) @synthesize的作用是实现属性的,如getter,setter方法. 在声明属性的情况下如果重写 ...
- scjp考试准备 - 7 - Java构造器
题目——如下代码的执行结果: class Hello{ String title; int value; public Hello(){ title += " World!"; } ...
- [工具]IL Mapper2(C# -> IL 转换器)
下载地址:IL_Mapper2_exe.zip 源文件:IL_Mapper2_src.zip 简介 此工具可以直接把C#代码转换成IL代码查看,省去编译和手动操作ildsam的繁琐.希望能对想研究IL ...
- forword属性
forword属性 2013年7月8日 15:07 Name: Forward的名字,与mapping.findForward方法传入的值相同. Path: 请求转发的页面路径 Redirect: 请 ...
- 【收藏】Linux下tomcat内存配置
常见的内存溢出有以下两种: java.lang.OutOfMemoryError: PermGen space java.lang.OutOfMemoryError: Java heap space ...
- 【每日scrum】NO.4
1.掌握了如何求两点间的最短距离这个算法.
- 【WildCard Matching】cpp
题目: Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single charact ...
- 利用checkbox的到值,并且存到数据库修改的话要显示之前选择的
在前台当然是利用checkbox来得到复选框的语言:{% for language in languages%}<input type="checkbox" name=&qu ...
- MySQL用程序代码建表(1)
一.创建表格代码格式 create table <表名>( <列名> <数据类型及长度> [not null], <列名> <数据类型及长度> ...
- POSⅨ thread
POSⅨ thread 简称为pthread,Posix线程是一个POSⅨ标准线程.该标准定义 内部API创建和操纵线程. 编辑本段作用 线程库实行了POSIX线程标准通常称为pthreads.POS ...