Uva-993 Product of digits(简单贪心)
来源:互联网 发布:智能网络摄像机哪个好 编辑:程序博客网 时间:2024/05/01 21:07
题目大意:
能否找到一个自然数q,使它每位上的数字的积,等于n,如果q存在,就输出q,不存在就输出-1
能否找到一个自然数q,使它每位上的数字的积,等于n,如果q存在,就输出q,不存在就输出-1
解析:这是一道简单的贪心题,从9到2,对n进行分解,然后把因数存在一个数组中,如过最后n > 1就输出-1,否则反向输出那个数组。
#include <cstdio>#include <cstring>using namespace std;const int N = 1000;int num[N];int main() {int t,n;scanf("%d",&t);while(t--) {scanf("%d",&n);if(n == 1) {printf("1\n");continue;}int cnt = 0;for(int i = 9; i >= 2; i--) {while(n % i == 0) {num[cnt++] = i;n /= i;}}if(n > 1) {printf("-1\n");}else {for(int i = cnt-1; i >= 0; i--) {printf("%d",num[i]);}printf("\n");}}return 0;}
0 0
- 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(简单数论)
- 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
- 获取指定目录下的文件
- [Objective-C]关联(objc_setAssociatedObject、objc_getAssociatedObject、objc_removeAssociatedObjects)
- 设计模式之---装饰者模式
- Opencv的奇葩问题
- android tabhost的用法
- Uva-993 Product of digits(简单贪心)
- 通俗解释matlab之遗传算法程序汇总与结果显示(三)
- 使用Axure制作无限循环展示图片效果
- HDU 1257 最少拦截系统(dp)
- 负载均衡(LVS+keepalived)
- 求任意两个正整数的和,无论它有多大,考虑溢出情况
- get_user,put_user与copy_from_user,copy_to_user
- poj 3427 Ecology tax
- swith case执行顺序