Code Forces 538 B. Quasi Binary(贪心)
来源:互联网 发布:js disabled 无效 编辑:程序博客网 时间:2024/05/22 00:09
Description
给出一个整数n,要求用m最少个数的只由0和1组成的数的和表示n
Input
一个整数n
Output
输出满足条件的数的个数m以及这m个数
Sample Input
9
Sample Output
1 1 1 1 1 1 1 1 1
Solution
贪心,尽量多用1,m就是n的各位数中的最大值
Code
#include<cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<functional>using namespace std;int n;int main(){ int num[10],num1[10],i=0,j,k,ans,g[10]; memset(g,0,sizeof(g)); scanf("%d",&n); while(n) { num1[i]=n%10; num[i++]=n%10; n/=10; } sort(num1,num1+i); ans=num1[i-1]; for(j=0;j<ans;j++) { for(k=i-1;k>=0;k--) { g[j]*=10; if(num[k]>0) { g[j]+=1; num[k]--; } } } printf("%d\n",ans); for(i=0;i<ans;i++) printf("%d ",g[i]); printf("\n");}
0 0
- Code Forces 538 B. Quasi Binary(贪心)
- CF 538B(Quasi Binary-贪心)
- cf-538B Quasi Binary【贪心】
- !codeforces 538B-Quasi Binary-(思维)
- CodeForces 538B Quasi Binary
- Codeforces - 538B - Quasi Binary
- Code Forces 583 B. Robot's Task(贪心)
- Code Forces 242 B. Big Segment 贪心
- CodeForces 538B Quasi Binary(简单数学)
- CodeForces 538B Quasi Binary(不错的贪心题 进制想法)
- codeforces 538 B.Quasi Binary(思维题)
- codeforces B. Quasi Binary
- B. Quasi Binary
- Code Forces 538 C. Tourist's Notes(贪心)
- Code Forces 276 B. Little Girl and Game 贪心
- 贪心-Code forces -387B -George and Round
- codeforces #300 B. Quasi Binary
- Code forces 699B
- POJ 2955 — Brackets 区间DP
- 环境变量:用户变量,系统变量区别
- KMP算法解决字符串匹配问题
- 守望者的逃离—贪心算法
- 7.24晚毫无准备的面试题
- Code Forces 538 B. Quasi Binary(贪心)
- RuntimeException异常
- GDB调试命令总结
- 【Android Studio】git的使用和总结
- leetcode[202]:Happy Number
- web开发网页嵌入flash
- Hibernate——三种状态的实例persistent演示
- C语言中的虚数
- HDU 2203 - 亲和串