Codeforces Round #292 (Div. 1)A. Drazil and Factorial 构造
A. Drazil and Factorial
题目连接:
http://codeforces.com/contest/516/problem/A
Description
Drazil is playing a math game with Varda.
Let's define for positive integer x as a product of factorials of its digits. For example, .
First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:
x doesn't contain neither digit 0 nor digit 1.
= .
Help friends find such number.
Input
The first line contains an integer n (1 ≤ n ≤ 15) — the number of digits in a.
The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
Output
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
Sample Input
4
1234
Sample Output
33222
Hint
题意
定义F(x)等于x的每一位的阶乘和。
现在给你一个a,然后让你找到一个最大的x,使得F(x)=F(a)
题解
a的顺序显然是没有关系的,对于每一个数的阶乘,其实只有唯一的对应最长的。
所以直接暴力去置换,然后排个序就好了。
代码
#include<bits/stdc++.h>
using namespace std;
string ans[10]={"","","2","3","322","5","53","7","7222","7332"};
int main()
{
int n;scanf("%d",&n);
string s1,s2;cin>>s1;
for(int i=0;i<s1.size();i++){
s2+=ans[s1[i]-'0'];
}
sort(s2.begin(),s2.end());
reverse(s2.begin(),s2.end());
cout<<s2<<endl;
}
Codeforces Round #292 (Div. 1)A. Drazil and Factorial 构造的更多相关文章
- Codeforces Round #292 (Div. 2) C. Drazil and Factorial 515C
C. Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces Round #292 (Div. 2) C. Drazil and Factorial
题目链接:http://codeforces.com/contest/515/problem/C 给出一个公式例如:F(135) = 1! * 3! * 5!; 现在给你一个有n位的数字a,让你求这样 ...
- Codeforces Round #292 (Div. 1) C. Drazil and Park 线段树
C. Drazil and Park 题目连接: http://codeforces.com/contest/516/problem/C Description Drazil is a monkey. ...
- Codeforces Round #292 (Div. 1) B. Drazil and Tiles 拓扑排序
B. Drazil and Tiles 题目连接: http://codeforces.com/contest/516/problem/B Description Drazil created a f ...
- Codeforces Round #292 (Div. 1) B. Drazil and Tiles (类似拓扑)
题目链接:http://codeforces.com/problemset/problem/516/B 一个n*m的方格,'*'不能填.给你很多个1*2的尖括号,问你是否能用唯一填法填满方格. 类似t ...
- Codeforces Round #292 (Div. 1) - B. Drazil and Tiles
B. Drazil and Tiles Drazil created a following problem about putting 1 × 2 tiles into an n × m gri ...
- Codeforces Round #292 (Div. 1) C - Drazil and Park
C - Drazil and Park 每个点有两个值Li 和 Bi,求Li + Rj (i < j) 的最大值,这个可以用线段树巧妙的维护.. #include<bits/stdc++. ...
- Codeforces Round #292 (Div. 2) D. Drazil and Tiles [拓扑排序 dfs]
传送门 D. Drazil and Tiles time limit per test 2 seconds memory limit per test 256 megabytes Drazil cre ...
- Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)
题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...
随机推荐
- bzoj千题计划281:bzoj4558: [JLoi2016]方
http://www.lydsy.com/JudgeOnline/problem.php?id=4558 容斥原理 全部的正方形-至少有一个点被删掉的+至少有两个点被删掉的-至少有3个点被删掉的+至少 ...
- github 远程仓库
因为本地Git仓库和GitHub仓库之间的传输是通过SSH加密的,所以设置一下 第1步:创建SSH Key.在用户主目录下,看看有没有.ssh目录,如果有,再看看这个目录下有没有id_rsa和id_r ...
- 移动端网页开发 meta 之 viewport
这几天在搞微信公众平台,涉及到几个页面要写,可是当我测试时发现和想象中不太一样,于是去找了几个页面看了下,发现他们页面头部有 meta viewport 的标签,所以去找了下网上的资料,发现千篇一律, ...
- 关于升级程序版本时version与build修改的问题
CHENYILONG Blog 关于升级程序版本时version与build修改的问题 #问题#从V1.0升级到V1.0.1.version是一定要改的,那么build需要修改吗? #解答#一般习惯上 ...
- Miller_Rabin 素数测试
费马定理的逆定理几乎可以用来判断一个数是否为素数,但是有一些数是判断不出来的,因此,Miller_Rabin测试方法对费马的测试过程做了改进,克服其存在的问题. 推理过程如下(摘自维基百科): 摘自另 ...
- spring如何管理mybatis(二) ----- SqlSession的线程安全性
在之前的文章中我们了解到最终的数据库最终操作是走的代理类的方法: @Override public Object invoke(Object proxy, Method method, Object[ ...
- 前端学PHP之正则表达式函数
前面的话 正则表达式不能独立使用,它只是一种用来定义字符串的规则模式,必须在相应的正则表达式函数中应用,才能实现对字符串的匹配.查找.替换及分割等操作.前面介绍了正则表达式的基础语法,本文将详细介绍正 ...
- LeetCode-Valid Number - 有限状态机
判断合法数字,之前好像在哪里看到过这题, 记得当时还写了好久,反正各种改, 今天看到了大神的解法(https://github.com/fuwutu/LeetCode/blob/master/Vali ...
- LVTTL与LVCMOS区别
TTL电平的VIH/VIL一般是2V/0.8V,VOH/VOL一般是 2.4V/0.4V,不论是3.3V还是5V的TTL都一样的:CMOS的VIH/VIL一般是70%VCC/30%VCC,VOH/VO ...
- mybatis延迟加载——(十二)
1. 什么是延迟加载 resultMap可以实现高级映射(使用association.collection实现一对一及一对多映射),association.collection具备延迟加载功能 ...