uva-993-贪心
题意:给你一个数字y,生成另外一个最小的数字x,使得x里面的每一位相乘等于y
解题思路:直接贪心就是,x里面的每一位都小于等于9
- #include <string>
- #include<iostream>
- #include<map>
- #include<memory.h>
- #include<vector>
- #include<algorithm>
- #include<queue>
- #include<vector>
- #include<stack>
- #include<math.h>
- #include<iomanip>
- #include<bitset>
- #include"math.h"
- namespace cc
- {
- using std::cout;
- using std::endl;
- using std::cin;
- using std::map;
- using std::vector;
- using std::string;
- using std::sort;
- using std::priority_queue;
- using std::greater;
- using std::vector;
- using std::swap;
- using std::stack;
- using std::queue;
- using std::bitset;
- constexpr int N = ;
- int a[N] = {};
- int l = ;
- void solve()
- {
- int n;
- cin >> n;
- long long Q;
- while (n--)
- {
- cin >> Q;
- memset(a,-,sizeof(a));
- l = ;
- if (Q == )
- {
- cout << << endl;
- continue;
- }
- while (Q!=)
- {
- int cur = ;
- for (int i = ;i >= ;i--)
- {
- if (Q >=i && Q%i==)
- {
- cur = i;
- break;
- }
- }
- if (cur == )
- {
- l = -;
- break;
- }
- a[l++] = cur;
- Q = Q / cur;
- }
- if (l == -)
- {
- cout << - << endl;
- }
- else
- {
- for (int i=l-;i>=;i--)
- {
- cout << a[i];
- }
- cout << endl;
- }
- }
- }
- };
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen("d://1.text", "r", stdin);
- #endif // !ONLINE_JUDGE
- cc::solve();
- return ;
- }
uva-993-贪心的更多相关文章
- uva 993 Product of digits (贪心 + 分解因子)
Product of digits For a given non-negative integer number N , find the minimal natural Q such tha ...
- 01_传说中的车(Fabled Rooks UVa 11134 贪心问题)
问题来源:刘汝佳<算法竞赛入门经典--训练指南> P81: 问题描述:你的任务是在n*n(1<=n<=5000)的棋盘上放n辆车,使得任意两辆车不相互攻击,且第i辆车在一个给定 ...
- UVA 11389(贪心问题)
UVA 11389 Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description II ...
- uva 10154 贪心+dp
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVa 11389 (贪心) The Bus Driver Problem
题意: 有司机,下午路线,晚上路线各n个.给每个司机恰好分配一个下午路线和晚上路线. 给出行驶每条路线的时间,如果司机开车时间超过d,则要付加班费d×r. 问如何分配路线才能使加班费最少. 分析: 感 ...
- UVa 1467 (贪心+暴力) Installations
题意: 一共有n项服务,每项服务有安装的时间s和截止时间d.对于每项任务,如果有一项超出截止时间,惩罚值为所超出时间的长度.问如何安装才能使惩罚值最大的两个任务的惩罚值之和最小. 分析: 如果是求总惩 ...
- Party Games UVA - 1610 贪心
题目:题目链接 思路:排序后处理到第一个不同的字符,贪心一下就可以了 AC代码: #include <iostream> #include <cstdio> #include ...
- UVa 1149 (贪心) Bin Packing
首先对物品按重量从小到大排序排序. 因为每个背包最多装两个物品,所以直觉上是最轻的和最重的放一起最节省空间. 考虑最轻的物品i和最重的物品j,如果ij可以放在一个包里那就放在一起. 否则的话,j只能自 ...
- UVa 993: Product of digits
这道题很简单.先将N用2,3,5,7(即10以内的素数)分解因数(需要先特殊判断N不为1),然后将可以合并的因数合并(如2*2合并成4,)这样求得的结果位数会减少,大小肯定会小一些.具体实现见代码. ...
- UVA 10037 贪心算法
题目链接:http://acm.hust.edu.cn/vjudge/contest/122829#problem/A 题目大意:N个人夜里过河,总共只有一盏灯,每次最多过两个人,然后需要有人将灯送回 ...
随机推荐
- sticky footer
html: <div class="detail"> <div class="detail-wrapper"> <div clas ...
- talk with gao about qssp
- 关于pdfbox操作pdf的分享链接手长
http://blog.csdn.net/fighting_no1/article/details/51038966
- window.location.href webkit不兼容
window.event.returnValue=false; 在location.href后加上后修复 来自为知笔记(Wiz)
- mysql命令行使用
连接数据库 mysql -P 端口号 -h 远程机地址/ip -u 用户名 -p mysql -uroot -p123456 修改数据库密码 mysqladmin -uroot -p123456 ...
- SQL-记录创建篇-006
创建记录: 自己添加记录: insert into table_name values(12,'张三',22) , values(1,'王五',32) insert into table_name(n ...
- 利用开源项目jadx反编译Android应用
原文转自:http://bbs.itheima.com/thread-200475-1-1.html 利用开源项目jadx反编译Android应用 利用Github开源项目jadx可以直接对 .dex ...
- 成功的拆开了SELECT里JOIN个SELECT是啥
SELECT * FROM table JOIN table ON a=b ----------------------- JOIN (SELECT* FROM table JOIN table ON ...
- PythonStudy——逻辑运算符 Logical Operators
在Python中,None.任何数值类型中的0.空字符串“”.空元组().空列表[].空字典{}都被当作False,还有自定义类型,如果实现了 __ nonzero __ () 或 __ len __ ...
- Amundsen — Lyft’s data discovery & metadata engine
转自:https://eng.lyft.com/amundsen-lyfts-data-discovery-metadata-engine-62d27254fbb9 In order to incre ...