cf-538B Quasi Binary【贪心】
来源:互联网 发布:java图形程序设计 编辑:程序博客网 时间:2024/06/08 16:24
cf-538B Quasi Binary
time limit per test2 seconds memory limit per test256 megabytes
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.
input
9
output
9
1 1 1 1 1 1 1 1 1
input
32
output
3
10 11 11
题目思路:贪心。比如说32–>3: 1 – 1 – 1 2: 1 – 1 – 0 所以,答案为11,11,10.
题目链接:cf 538B
以下是代码:
#include <vector>#include <map>#include <set>#include <algorithm>#include <iostream>#include <cstdio>#include <cmath>#include <cstdlib>#include <string>#include <cstring>using namespace std;int main(){ int n; cin >> n; vector <int> a; int maxsize = 0; for(int i = 0; n; i++) { a.push_back(n % 10); if (n % 10 > maxsize) maxsize = n % 10; //求出可以拆分成几个数字 n /= 10; } reverse(a.begin(),a.end()); cout << maxsize << endl; for (int i = 0; i < maxsize ;i++) { bool flag = 0; for (int j = 0; j < a.size(); j++) { if (a[j] > 0) { flag = 1; a[j]--; cout << 1; } else if (flag) cout << 0; } cout << " "; } return 0;}
- CF 538B(Quasi Binary-贪心)
- cf-538B Quasi Binary【贪心】
- Code Forces 538 B. Quasi Binary(贪心)
- CodeForces 538B Quasi Binary
- Codeforces - 538B - Quasi Binary
- CodeForces 538B Quasi Binary(不错的贪心题 进制想法)
- codeforces 538 B.Quasi Binary(思维题)
- !codeforces 538B-Quasi Binary-(思维)
- codeforces B. Quasi Binary
- B. Quasi Binary
- codeforces #300 B. Quasi Binary
- CodeForces 538B Quasi Binary(简单数学)
- Codeforces Round #300 - Quasi Binary(贪心)
- #300 (div.1 2) B. Quasi Binary
- contest: Codeforces Round #300, problem: (B) Quasi Binary
- 贪心 CF 333B Chips
- cf 484B 二分+贪心
- 模拟:Quasi Binary
- HDU 4455 线段树
- android学习笔记 内容提供者
- 用类加载器的方式管理资源和配置文件
- xUtils系列之DbUtils-增,删,更新,替换操作
- POJ 2406 KMP
- cf-538B Quasi Binary【贪心】
- POJ 2823 单调队列
- POJ 3321 树状数组
- UML简单介绍(二)——UML中的图及其特征
- POJ 3461 KMP
- JAR WAR EAR包的区别
- e5-5uva12096
- Restful 406 Not Acceptable
- POJ - 3484 Showstopper 二分搜索