题意:给你一个数字y,生成另外一个最小的数字x,使得x里面的每一位相乘等于y

解题思路:直接贪心就是,x里面的每一位都小于等于9

  1. #include <string>
  2. #include<iostream>
  3. #include<map>
  4. #include<memory.h>
  5. #include<vector>
  6. #include<algorithm>
  7. #include<queue>
  8. #include<vector>
  9. #include<stack>
  10. #include<math.h>
  11. #include<iomanip>
  12. #include<bitset>
  13. #include"math.h"
  14. namespace cc
  15. {
  16. using std::cout;
  17. using std::endl;
  18. using std::cin;
  19. using std::map;
  20. using std::vector;
  21. using std::string;
  22. using std::sort;
  23. using std::priority_queue;
  24. using std::greater;
  25. using std::vector;
  26. using std::swap;
  27. using std::stack;
  28. using std::queue;
  29. using std::bitset;
  30.  
  31. constexpr int N = ;
  32. int a[N] = {};
  33. int l = ;
  34. void solve()
  35. {
  36. int n;
  37. cin >> n;
  38. long long Q;
  39. while (n--)
  40. {
  41. cin >> Q;
  42. memset(a,-,sizeof(a));
  43. l = ;
  44. if (Q == )
  45. {
  46. cout << << endl;
  47. continue;
  48. }
  49.  
  50. while (Q!=)
  51. {
  52. int cur = ;
  53. for (int i = ;i >= ;i--)
  54. {
  55. if (Q >=i && Q%i==)
  56. {
  57. cur = i;
  58. break;
  59. }
  60. }
  61. if (cur == )
  62. {
  63. l = -;
  64. break;
  65. }
  66. a[l++] = cur;
  67. Q = Q / cur;
  68. }
  69. if (l == -)
  70. {
  71. cout << - << endl;
  72. }
  73. else
  74. {
  75. for (int i=l-;i>=;i--)
  76. {
  77. cout << a[i];
  78. }
  79. cout << endl;
  80. }
  81. }
  82.  
  83. }
  84. };
  85.  
  86. int main()
  87. {
  88.  
  89. #ifndef ONLINE_JUDGE
  90. freopen("d://1.text", "r", stdin);
  91. #endif // !ONLINE_JUDGE
  92. cc::solve();
  93.  
  94. return ;
  95. }

uva-993-贪心的更多相关文章

  1. uva 993 Product of digits (贪心 + 分解因子)

      Product of digits  For a given non-negative integer number N , find the minimal natural Q such tha ...

  2. 01_传说中的车(Fabled Rooks UVa 11134 贪心问题)

    问题来源:刘汝佳<算法竞赛入门经典--训练指南> P81: 问题描述:你的任务是在n*n(1<=n<=5000)的棋盘上放n辆车,使得任意两辆车不相互攻击,且第i辆车在一个给定 ...

  3. UVA 11389(贪心问题)

    UVA 11389 Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description II  ...

  4. uva 10154 贪心+dp

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  5. UVa 11389 (贪心) The Bus Driver Problem

    题意: 有司机,下午路线,晚上路线各n个.给每个司机恰好分配一个下午路线和晚上路线. 给出行驶每条路线的时间,如果司机开车时间超过d,则要付加班费d×r. 问如何分配路线才能使加班费最少. 分析: 感 ...

  6. UVa 1467 (贪心+暴力) Installations

    题意: 一共有n项服务,每项服务有安装的时间s和截止时间d.对于每项任务,如果有一项超出截止时间,惩罚值为所超出时间的长度.问如何安装才能使惩罚值最大的两个任务的惩罚值之和最小. 分析: 如果是求总惩 ...

  7. Party Games UVA - 1610 贪心

    题目:题目链接 思路:排序后处理到第一个不同的字符,贪心一下就可以了 AC代码: #include <iostream> #include <cstdio> #include ...

  8. UVa 1149 (贪心) Bin Packing

    首先对物品按重量从小到大排序排序. 因为每个背包最多装两个物品,所以直觉上是最轻的和最重的放一起最节省空间. 考虑最轻的物品i和最重的物品j,如果ij可以放在一个包里那就放在一起. 否则的话,j只能自 ...

  9. UVa 993: Product of digits

    这道题很简单.先将N用2,3,5,7(即10以内的素数)分解因数(需要先特殊判断N不为1),然后将可以合并的因数合并(如2*2合并成4,)这样求得的结果位数会减少,大小肯定会小一些.具体实现见代码. ...

  10. UVA 10037 贪心算法

    题目链接:http://acm.hust.edu.cn/vjudge/contest/122829#problem/A 题目大意:N个人夜里过河,总共只有一盏灯,每次最多过两个人,然后需要有人将灯送回 ...

随机推荐

  1. sticky footer

    html: <div class="detail"> <div class="detail-wrapper"> <div clas ...

  2. talk with gao about qssp

  3. 关于pdfbox操作pdf的分享链接手长

    http://blog.csdn.net/fighting_no1/article/details/51038966

  4. window.location.href webkit不兼容

    window.event.returnValue=false; 在location.href后加上后修复 来自为知笔记(Wiz)

  5. mysql命令行使用

    连接数据库   mysql -P 端口号 -h 远程机地址/ip -u 用户名 -p mysql -uroot -p123456 修改数据库密码 mysqladmin -uroot -p123456 ...

  6. SQL-记录创建篇-006

    创建记录: 自己添加记录: insert into table_name values(12,'张三',22) , values(1,'王五',32) insert into table_name(n ...

  7. 利用开源项目jadx反编译Android应用

    原文转自:http://bbs.itheima.com/thread-200475-1-1.html 利用开源项目jadx反编译Android应用 利用Github开源项目jadx可以直接对 .dex ...

  8. 成功的拆开了SELECT里JOIN个SELECT是啥

    SELECT * FROM table JOIN table ON a=b ----------------------- JOIN (SELECT* FROM table JOIN table ON ...

  9. PythonStudy——逻辑运算符 Logical Operators

    在Python中,None.任何数值类型中的0.空字符串“”.空元组().空列表[].空字典{}都被当作False,还有自定义类型,如果实现了 __ nonzero __ () 或 __ len __ ...

  10. Amundsen — Lyft’s data discovery & metadata engine

    转自:https://eng.lyft.com/amundsen-lyfts-data-discovery-metadata-engine-62d27254fbb9 In order to incre ...