开启博客园

记录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的更多相关文章

  1. Codeforces Round #300 B. Quasi Binary 水题

    B. Quasi Binary Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/probl ...

  2. Codeforces Round #300 Quasi Binary(DP)

    Quasi Binary time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  3. Codeforces 538 B. Quasi Binary

    B. Quasi Binary   time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  4. CF538B Quasi Binary 思维题

    题目描述 给出一个数 \(n\),你需要将 \(n\) 写成若干个数的和,其中每个数的十进制表示中仅包含\(0\)和\(1\). 问最少需要多少个数 输入输出格式 输入格式: 一行 一个数 \(n(1 ...

  5. Codeforces Round #300(A.【字符串,多方法】,B.【思维题】,C.【贪心,数学】)

    A. Cutting Banner time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  6. Codeforces Round #300 解题报告

    呜呜周日的时候手感一直很好 代码一般都是一遍过编译一遍过样例 做CF的时候前三题也都是一遍过Pretest没想着去检查... 期间姐姐提醒说有Announcement也自信不去看 呜呜然后就FST了 ...

  7. [数据结构]——二叉树(Binary Tree)、二叉搜索树(Binary Search Tree)及其衍生算法

    二叉树(Binary Tree)是最简单的树形数据结构,然而却十分精妙.其衍生出各种算法,以致于占据了数据结构的半壁江山.STL中大名顶顶的关联容器--集合(set).映射(map)便是使用二叉树实现 ...

  8. ILJMALL project过程中遇到Fragment嵌套问题:IllegalArgumentException: Binary XML file line #23: Duplicate id

    出现场景:当点击"分类"再返回"首页"时,发生error退出   BUG描述:Caused by: java.lang.IllegalArgumentExcep ...

  9. Leetcode 笔记 110 - Balanced Binary Tree

    题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...

随机推荐

  1. ExtJS MVC学习手记 2

    开发环境 eclipse(indigo) ExtJS4.0 开发目标 使用store.model和controller创建菜单树 开发步骤 之前我们已经建立了一个MVC的项目框架.现在要做的就是在这个 ...

  2. [转]webrtc学习: 部署stun和turn服务器

    [转]webrtc学习: 部署stun和turn服务器 http://www.cnblogs.com/lingdhox/p/4209659.html webrtc的P2P穿透部分是由libjingle ...

  3. 28.USB的传输类型

    USB上必须将数据组织成 事务 才能够进行传输.事务常有两个或三个包.令牌包用于启动一个事务,由主机发送:数据包传送数据,方向由令牌包确定:握手包常是数据接收方发送的,用于表示接收数据的状态.USB协 ...

  4. OC中成员变量的命名

    先前写C++ 的时候,命名成员变量一般都是用 m_veriableName:的方式,但是进到新项目组,用了OC以后,发现成员变量都是用 veriableName_的方式,最后的一个下划线表示是成员变量 ...

  5. How to check if NSString begins with a certain character

    How to check if NSString begins with a certain character How do you check if an NSString begins with ...

  6. SqlServer中Sql语句的逻辑执行顺序

    准备数据 Sql脚本如下,两张表,一张客户表Customers只包含customerid和city字段,一张订单表Orders包含orderid和customerid(关联Customers的cust ...

  7. C语言编写的随机产生四则运算测试题

    题目:编写一个四则运算测试题的程序,要求每道题都要随机产生 解题思路: 1.编写测试题,且为30道,就要用到循环函数,因此想到用for()函数 2.随机产生两个数,就想到用rand()函数. 注:1. ...

  8. VS2013 IIS Express 添加MIME映射

    VS2013,则可以直接在IIS Express中添加MIME映射.操作如下: 1.在DOS窗口下进入IIS Express安装目录,默认是“C:\Program Files\IIS Express” ...

  9. Xamarin.Android之转换,呼叫,查看历史纪录

    Xamarin.Android之转换,呼叫,查看历史纪录 E文文章. 功能:能将输入的字母转换成相应的数字.并且能呼叫出去.能查看呼叫的历史纪录. 界面代码如下: <?xml version=& ...

  10. 解决a different object with the same identifier value was already associated with the session错误

    [转]解决a different object with the same identifier value was already associated with the session错误 这个错 ...