(贪心5.2.6)URAL 1014 Product of Digits(利用数据有序化进行贪心选择)
来源:互联网 发布:创业网络平台建设 编辑:程序博客网 时间:2024/04/30 20:27
/* * URAL_1014.cpp * * Created on: 2013年10月11日 * Author: Administrator */#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;const int maxn = 11;int a[maxn];int main() {int n;scanf("%d", &n);if (n == 0) {printf("10\n");return 0;}if (n == 1) {printf("1\n");return 0;}int num = 0;while (n > 1) {int i;bool flag = false;for (i = 9; i >= 2; --i) {//之所以从9开始扫是为了让分解出来的因子的高位数字小、少if (n % i == 0) {//找到了其中一个因子a[num++] = i;n /= i;flag = true;//依据题意,每次扫的时候都应该能从在2~9中找到一个因子邹泽则是不可分解的break;//没找到一个因子以后都要重新扫..}}if(!flag){//这句话一定要加上,及应该在这里就进行判断,看这个数能否进行分解。否则就会出现死循环...如23 就不能进行分解printf("-1\n");return 0;}}sort(a, a + num);int i;for (i = 0; i < num; ++i) {printf("%d", a[i]);}return 0;}
- (贪心5.2.6)URAL 1014 Product of Digits(利用数据有序化进行贪心选择)
- URAL 1014 Product of Digits 贪心
- ural 1014. Product of Digits贪心
- (贪心5.2.1)UVA 10026 Shoemaker's Problem(利用数据有序化来进行贪心选择)
- (贪心5.2.2)UVA 10954 Add All(利用数据的有序化来进行贪心选择)
- (贪心5.2.3)POJ 1065 Wooden Sticks(利用数据有序化来进行贪心选择)
- (贪心5.2.5)POJ 1862 Stripies(利用数据有序化来进行贪心选择)
- (贪心5.2.9)UVA 10020 Minimal coverage(利用数据有序化来进行贪心选择)
- (贪心5.2.4)ZOJ 1360 Radar Installation(对有序化数据进行贪心选择)
- ural 1014 Product of Digits
- URAL 1014 Product of Digits
- (Relax 1.6)POJ 1328 Radar Installation(利用数据有序化进行贪心选择)
- 993 - Product of digits(贪心)
- UVA - 993 Product of digits 贪心
- 10 URAL 1014 Product of Digits
- Ural 1014 Product of Digits 解题报告
- ural 1014 the product of digits
- uva 993Product of digits (贪心 + 分解因子)
- Linux就是这个范儿之第一次亲密接触(3)
- WEB开发总结(持续更新。。。)
- 14条建议,使你的IT职业生涯更上一层楼
- php学习笔记 1
- 每天一小步——C语言中嵌入正则表达式
- (贪心5.2.6)URAL 1014 Product of Digits(利用数据有序化进行贪心选择)
- 继承机制
- Pat1034
- Shell 单引号 双引号 反引号
- css学习
- 瑞杰php速查手册forAndroid ver0.0.1build20131007
- UDA1341声卡驱动修改
- 教你如何成为程序员高手
- JVM内存模型及内存分配过程