您的位置:首页 > 其它

B. Quasi Binary

2015-07-21 20:20 155 查看
开启博客园

记录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,
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: