UVA 993Product of digits 数字之积 贪心水题
来源:互联网 发布:java collection sort 编辑:程序博客网 时间:2024/05/16 03:19
题意:求出一个数,各个位数上相乘的积等于所给的数。
枚举2-9,如果找到一个数能整除那个数就枚举下一位,递归即可。
代码:
/* * Author: illuz <iilluzen[at]gmail.com> * Blog: http://blog.csdn.net/hcbbt * File: uva993.cpp * Lauguage: C/C++ * Create Date: 2013-09-01 00:24:29 * Descripton: uva993, brute */#include <cstdio>#define rep(i, n) for (int i = 0; i < (n); i++)const int MAXN = 100;bool flag;int t, n, a[20], cnt;void solve(int d) {if (flag) return;if (!n) return;n /= 10;for (int i = 9; i >= 2 && !flag; i--) {if (d % i == 0) {solve(d / i);a[cnt++] = i;return;}}flag = true;}int main() {scanf("%d", &t);while (t--) {scanf("%d", &n);if (n == 1) {printf("1\n");continue;}if (n == 0) {printf("0\n");continue;}flag = false;cnt = 0;solve(n);if (!flag) rep(i, cnt) printf("%d", a[i]);else printf("-1");printf("\n");}return 0;}
- UVA 993Product of digits 数字之积 贪心水题
- UVA - 993 Product of digits 贪心
- uva 993Product of digits (贪心 + 分解因子)
- uva - 993 - Product of digits(贪心法)
- Uva-993 Product of digits(简单贪心)
- UVA - 993 - Product of digits (简单贪心)
- UVa 993 - Product of digits
- UVa 993 - Product of digits
- uva 993 - Product of digits
- uva 993 - Product of digits
- UVA 993 Product of digits
- UVa 993 - Product of digits
- Uva 993 Product Of Digits
- UVA 993 - Product of digits
- uva 993 - Product of digits
- UVa 993: Product of digits
- UVa:993 Product of digits
- uva 993 Product of digits
- javacookie
- 双链表实现
- 自动化与性能测试集成-极品干货!!!
- 在线调试和演示前端开发工具
- 轻量级性能测试工具ContiPerf
- UVA 993Product of digits 数字之积 贪心水题
- 基于selenium的自动化测试框架
- Fedora 6 安装中文语言包
- 使用Jsoup解析HTML页面
- 【软件推荐】Sublime Text,一款为写码子而生的编辑器
- 【转载】HBase 系统架构
- junit4.11 NoClassDefFoundError的错误
- POJ_2723题解
- unable to open 'C:/Program Files/Adobe/Adobe Flash Builder Beta 2/sdks/3.4.1/frameworks/locale/zh_C