CodeForces 538B
Description
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
Input
The first line contains a single integer n (1 ≤ n ≤ 106).
Output
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
Sample Input
9
9
1 1 1 1 1 1 1 1 1
32
3
10 11 11
解题思路:题目大意:将一个数拆分成几个由1和0组成的数。输出数的个数以及各个拆分后的数。
当n小于9的时候,只能拆分成n个1;
当n大于9时,用一个数组将n的各个位数存起来,其中最大的那个数Max则为输出数的个数;
输出时,共有Max个循环对数组输出,当数组元素大于等于1时,输出1,同时元素值减一;当数组元素等于0时,输出0;
注意:当数组输出的第一个数为0时选择不输出。直到第一个数不为0时输出。
#include<iostream>
#include<stdio.h>
#include<cstring> using namespace std;
int c[];
int main()
{
string s;
cin>>s;
int sum; if(s.length()==){
printf("%d\n",s[]-'');
for(int i=;i<=s[]-'';i++)
{
if(i==) printf("");
else
printf("");
}
printf("\n");
} else
{
int k=s.length();
for(int i=;i<=s.length();i++)
c[i]=s[s.length()-i]-'';
int Max=;
for(int i=;i<=k;i++)
{
if(c[i]>Max) Max=c[i];
}
printf("%d\n",Max);
while(Max--)
{
int i;int j=;
for(i=k;i>=;i--)
{
//cout<<i<<"H"<<c[i]<<endl;
if(c[i]==&&j==) {continue;}
else
{
j++;
if(c[i]!=){printf("");c[i]=c[i]-;}
else printf("");
}
}
printf(" ");
}
printf("\n"); }
return ;
}
CodeForces 538B的更多相关文章
- Codeforces Round #300(Div. 2)-538A.str.substr 538B.不会 538C.不会 。。。
A. Cutting Banner time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- MSSQLSERVER数据库- 作业调度定时备份数据库
作业调度和备份数据库是常见的行为,掌握这两项技术我觉的非常有必要. 在网上找到这个示例,记录在这里 备份数据库的SQL语句 --自动备份并保存最近5天的SQL数据库作业脚本 ) DECLARE @da ...
- 使用JavaScript实现分页效果
应公司需求,有时需要制作静态页面网站,而一旦涉及到文章的分页,实现起来非常麻烦,自己又刚入门,对js不是很熟悉,所以就拿来练练手. 首先页面结构如下,分别展示数据跟分页: <!DOCTYPE h ...
- Xcode7如何添加pch文件
我们在写项目的时候,大部分宏定义,头文件导入都在这里,Xcode6去掉Precompile Prefix Header的主要原因可能在于Prefix Header大大的增加了Build的时间.但是没有 ...
- JBoss7快速入门
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- Microsoft.AspNet.FriendlyUrls发布到IIS后404报错的解决方案
我一个项目都基本上做完了,结果部署到我服务器的时候结果一直报404 找不到 一看global.asax有个路由注册的代码 public static void RegisterRoutes(Route ...
- C#-创建自定义双击事件
.NET Compact Framework 不支持按钮的 Windows 窗体 DoubleClick 事件.但是您可以创建一个从 Button 类派生的控件来实现该事件. 创建自定义双击事件 创建 ...
- Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp
B. Modulo Sum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/ ...
- [AngularJS] angular-schema-form -- 1
Check out on gitHub, see the example on Demo page, see the document, extension. Mainly, there are th ...
- 编写一个程序,从标准输入中读取若干string对象并查找连续重复出现的单词。所谓连续重复出现的意思是:一个单词后面紧跟着这个单词本身。要求记录连续重复出现的最大次数以及对应的单词
#include<iostream> #include<string> #include<vector> using namespace std; int main ...
- PAT 1005
1005. Spell It Right (20) Given a non-negative integer N, your task is to compute the sum of all the ...