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 ...
随机推荐
- Linux下cron的使用
cron是一个linux下的定时执行工具,可以在无需人工干预的情况下运行作业.由于Cron 是Linux的内置服务,但它不自动起来,可以用以下的方法启动.关闭这个服务: /sbin/service c ...
- [转]windows 软链接的建立及删除
[转]windows 软链接的建立及删除 http://blog.chinaunix.net/uid-74941-id-3764093.html 1.建立举例 ##建立d:develop链接目录,指向 ...
- 团队开发——SCRUM报告(一)
一.成员介绍 队长:胡亚宝 PM:曹美娜 成员:焦燕.袁亚姣.黄亚萍 二.sprint会议 由于之前是一五一小长假,所以距离上次会议中间隔了很长时间,这里在对上次会议做一下简单的汇总 在上次会议上我们 ...
- Careercup - Google面试题 - 6331648220069888
2014-05-08 22:27 题目链接 原题: What's the tracking algorithm of nearest location to some friends that are ...
- 《我是IT小小鸟》读书笔记
转眼间,大学的第二学期悄悄来临了,老师给我们布置了一道原本我以为很无趣的题目----写<我是IT的读书笔记>,但是我读了<我是IT小小鸟>这本书后,令我受益匪浅:五个人,每个人 ...
- LAMP一键安装包-CentOS 5/6下自动编译安装Apache,MySQL,PHP
http://www.centos.bz/lamp/ 此安装包已经不再维护,请使用新版http://www.centos.bz/ezhttp/. 适用环境: 系统支持:CentOS-5 (32bit/ ...
- Codeforces Round #253 (Div. 2) D题
题目大意是选出一个其他不选,问问最大概率: 刚开始想到DP:F[I][J][0]:表示从 前I个中选出J个的最大值, 然后对于F[I][J][1]=MAX(F[I-1][J][1],F[I-1][J- ...
- 实现WMSservice的时候,出现边缘的点或icon被切断的情况
可以通过为实际查询的boundary加一个buffer,使查询的范围比指定的大一点点,这样就会使tile之间在查询的时候有一定的重叠. 如:Geometry queryBoundary = JTS.t ...
- Unity 处理策划的 Excel
很多时候我们需要使用策划的Excel表来做游戏的静态数据配置, 而不是采用自己定义的xml或者U3D的scriptobject. 因为很多数据都是策划处理的,而策划最喜欢的就是excel,也只会用这个 ...
- Unity上使用Linq To XML
using UnityEngine; using System.Collections; using System.Linq; using System.Xml.Linq; using System; ...