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个人夜里过河,总共只有一盏灯,每次最多过两个人,然后需要有人将灯送回 ...
随机推荐
- atom插件安装失败解决方法
在atom 上下载插件失败,可以用下面的方法. 1.找到C:/Users/你的用户名/.atom/packages/文件夹内 2.在.atom packages 目录下 使用gitbash 3.git ...
- Maximum Average Subarray
Given an array with positive and negative numbers, find the maximum average subarray which length sh ...
- python面向对象的基础语法(dir内置函数、self参数、初始化方法、内置方法和属性)
面相对象基础语法 目标 dir 内置函数 定义简单的类(只包含方法) 方法中的 self 参数 初始化方法 内置方法和属性 01. dir 内置函数(知道) 在 Python 中 对象几乎是无所不在的 ...
- linux之创建用户
用户 useradd xxx 创建用户 默认是普通用户 useradd -u666 web 创建新用户 设置id号 groupadd -g 777 ...
- Mac + PyCharm 安装 Opencv3 + python2.7
本文地址:http://www.cnblogs.com/QingHuan/p/7354074.html 转载请注明本文地址,方便读者查看本文更新,谢谢! 今天要在Mac上安装OpenCV,过程非常曲折 ...
- 编写简单的windows桌面计算器程序
编译环境:VS2017 主文件为: #include "stdafx.h" #include "WindowsProject5.h" #include &quo ...
- 解决使用C/C++配置ODBC链接中文显示为问号(?)的问题
使用VS2015中使用OBDC连接到数据库时,数据库可以正常显示,但是在VS上输出是乱码,如图: 在数据库中course表显示: vs程序结果显示: 查找原因,因为char默认读ascii型,只读到1 ...
- day05 判断敏感字符
1.判断一个字符是不是敏感字符: in 1.str v ="年龄多大了" if "大" in v: print("敏感") 2.list/t ...
- PTA——黑洞数
PTA 7-44 黑洞数 我的程序,一个用例通不过 #include<stdio.h> void sort(int *a,int n); int main() { ; scanf(&quo ...
- python:Hamlet英文词频统计
#CalHamletV1.py def getText(): #定义函数读取文件 txt = open("hamlet.txt","r").read() txt ...