codeforces 515C. Drazil and Factorial
来源:互联网 发布:信永中和最新工资算法 编辑:程序博客网 时间:2024/05/21 09:15
题目链接: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 <string.h>using namespace std;int main(){#ifndef ONLINE_JUDGE freopen("1.txt", "r", stdin);#endif int n, i, j, b[10]; char a[20]; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); cin >> n; scanf("%s", a); for (i = 0; i < n; i++) { j = a[i] - '0'; switch(j) { case 2: case 3: case 5: case 7: b[j]++; break; case 4: b[3]++; b[2] += 2; break; case 6: b[5]++; b[3]++; break; case 8: b[7]++; b[2] += 3; break; case 9: b[7]++; b[3] += 2; b[2]++; break; } } for (i = 9; i > 1; i--) { for (j = 0; j < b[i]; j++) { cout << i; } } return 0;}
0 0
- Codeforces 515C Drazil and Factorial
- Codeforces 515C Drazil and Factorial
- codeforces 515C. Drazil and Factorial
- Codeforces-515C-Drazil and Factorial
- CodeForces - 515C Drazil and Factorial
- codeforces 515C Drazil and Factorial
- 【CodeForces】C. Drazil and Factorial
- 515C. Drazil and Factorial
- codeforces 515c Drazil and Factorial 分类讨论
- Drazil and Factorial - CodeForces 513 C 水题
- Codeforces #292C. Drazil and Factorial 数学
- 【CodeForces 513C】Drazil and Factorial
- C. Drazil and Factorial
- C. Drazil and Factorial
- C. Drazil and Factorial
- Codeforce 515 C . Drazil and Factorial 规律
- Codeforces Round #292 (Div. 2) -- C. Drazil and Factorial
- Codeforces Round #292 (Div. 2) Problem C - Drazil and Factorial
- C++中const、volatile、mutable用法小结
- OC中protocol协议
- 安卓开发文档自翻译~(1)--adb
- 零基础学C语言 笔记五 算术表达式
- 强制类型转换
- codeforces 515C. Drazil and Factorial
- http协议
- 接口关系下的多态
- 开发工具之Eclipse快捷键
- 微信抢红包优化版
- Python 中怎么写 swap()交换函数
- 关于mutex的一些思考
- 共享文件
- HDU 5352(MZL's City-费用流)