codeforces 515C. Drazil and Factorial 解题报告
题目链接:http://codeforces.com/problemset/problem/515/C
题目意思:给出含有 n 个只有阿拉伯数字的字符串a(可能会有前导0),设定函数F(a) = 每个数字的阶乘乘积。例如 F(135) = 1! * 3! * 5! 。需要找出 x,使得F(x) = F(a),且组成 x 的数字中没有0和1。求最大的 x 为多少。
这个我是看了每个数字的转换才知道怎么做的。
0, 1 —— > empty(用空串表示)
2 —— > 2
3 —— > 3
4 —— > 322
5 —— > 5
6 —— > 53
7 —— > 7
8 —— > 7222
9 —— > 7332
然后保存这些转换,转换完之后排一下序就是答案了。
要特别注意 ans 开的数组大小,n 最大为15,考虑全部是9的情况,转换后为4个数字,即开到4 * 15 = 60 就差不多了。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = + ;
const int N = + ;
char convert[maxn][maxn] = {"", "", "", "", "", "", "", "", "", ""};
char s[maxn];
char ans[N]; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE int n;
while (scanf("%d", &n) != EOF) {
scanf("%s", s);
int cnt = ;
for (int i = ; i < n; i++) {
int len = strlen(convert[s[i]-'']);
for (int j = ; j < len; j++)
ans[cnt++] = convert[s[i]-''][j];
}
sort(ans, ans+cnt);
reverse(ans, ans+cnt);
for (int i = ; i < cnt; i++)
printf("%c", ans[i]);
puts("");
}
return ;
}
codeforces 515C. Drazil and Factorial 解题报告的更多相关文章
- CodeForces 515C. Drazil and Factorial
C. Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- codeforces 515A.Drazil and Date 解题报告
题目链接:http://codeforces.com/problemset/problem/515/A 题目意思:问能否从 (0, 0) 出发,恰好走 s 步,到达该位置(a, b). 首先容易知道, ...
- CodeForces 515C Drazil and Factorial (水题)
题意:给出含有 n 个只有阿拉伯数字的字符串a,设定函数F(a) = 每个数字的阶乘乘积 .需要找出 x,使得F(x) = F(a),且组成 x 的数字中没有0和1.求最大的 x 为多少. 析:最大, ...
- Codeforces Educational Round 92 赛后解题报告(A-G)
Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...
- codeforces 476C.Dreamoon and Sums 解题报告
题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...
- Codeforces Round #382 (Div. 2) 解题报告
CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...
- codeforces 507B. Amr and Pins 解题报告
题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...
- codeforces 500B.New Year Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...
- codeforces B. Xenia and Ringroad 解题报告
题目链接:http://codeforces.com/problemset/problem/339/B 题目理解不难,这句是解题的关键 In order to complete the i-th ta ...
随机推荐
- jQuery.validator 验证规则详解
前言:jQuery.validator是一款非常不错的表单验证插件,验证方式非常简单方便,它还对HTML5做了兼容处理,了解了验证规则,就基本掌握了它的使用,下面就让我一一道来 jQuery.vali ...
- Apache中,同一IP使用多域名对应多个网站的方法
首先dns中确定有相应的A记录, abc IN A 211.154.2.5 mail IN A 211.154.2.5 这个讲的是在windows下面配置apache虚拟主机: 一.配置虚拟 ...
- 机器码call和jmp地址的计算
call和jmp都是跳转指令,但是call的同时会把pc地址压入堆栈,并且这两种方式都有远和近跳转.下面的分析不全,因为没有在网上找到足够的资料,个人创造这个情景还是有些困难. 1.例子中的call的 ...
- Google Protocol Buffer 简单介绍
以下内容主要整理自官方文档. 为什么使用 Protocol Buffers .proto文件 Protocol Buffers 语法 编译.proto文件 Protocol Buffers API 枚 ...
- 【codevs1380】没有上司的舞会
题目描述 Ural大学有N个职员,编号为1~N.他们有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子结点的直接上司.每个职员有一个快乐指数.现在有个周年庆宴会,要求与会职员的快乐指数 ...
- 2015多校.MZL's endless loop(欧拉回路的机智应用 || 构造)
MZL's endless loop Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Oth ...
- docker镜象
1.安装好docker后,用docker命令的时候有时候会报错:Post http:///var/run/docker.sock/v1.19/images/create?fromImage=ubunt ...
- css 3d 动画 相关
transform-style: preserve-3d; 设置3D模式 perspective:700px :属性定义 3D 元素距视图的距离,以像素计.该属性允许您改变 3D 元素查看 3D 元素 ...
- OpenCV图像的缩放
函数介绍: 1.cvResize 改变图像大小 void cvResize(const CvArr *src, CvArr *dst, int interpolation) 函数说 ...
- MyEclipse 15 集成SVN
一.在线更新 地址:http://subclipse.tigris.org/update_1.8.x 二.手动安装