码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces 515C. Drazil and Factorial 解题报告

时间:2015-02-18 21:01:27      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

题目链接: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 就差不多了。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <algorithm>
 6 using namespace std;
 7 
 8 const int maxn = 15 + 5;
 9 const int N = 100 + 5;
10 char convert[maxn][maxn] = {"", "", "2", "3", "322", "5", "53", "7", "7222", "7332"};
11 char s[maxn];
12 char ans[N];
13 
14 int main()
15 {
16     #ifndef ONLINE_JUDGE
17         freopen("in.txt", "r", stdin);
18     #endif // ONLINE_JUDGE
19 
20     int n;
21     while (scanf("%d", &n) != EOF) {
22         scanf("%s", s);
23         int cnt = 0;
24         for (int i = 0; i < n; i++) {
25             int len = strlen(convert[s[i]-0]);
26             for (int j = 0; j < len; j++)
27                 ans[cnt++] = convert[s[i]-0][j];
28         }
29         sort(ans, ans+cnt);
30         reverse(ans, ans+cnt);
31         for (int i = 0; i < cnt; i++)
32             printf("%c", ans[i]);
33         puts("");
34     }
35     return 0;
36 }

 

 

 

codeforces 515C. Drazil and Factorial 解题报告

标签:

原文地址:http://www.cnblogs.com/windysai/p/4295917.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!