Codeforces Round #292 (Div. 2) C. Drazil and Factorial

题目链接:http://codeforces.com/contest/515/problem/C

给出一个公式例如:F(135) = 1! * 3! * 5!;

现在给你一个有n位的数字a,让你求这样一个x,满足x中没有0和1,F(a) = F(x),然后就是x要最大.

当x的位数比a多或者从高位开始x的数某一位要大于a的某一位,然后第二种显然是不可能的,所以我们寻找如何把a变长的方法.

例如数字

4! = 1 * 2 * 3 * 4

    =3! * 2 * 2

    =3! * 2! * 2!

所以当a中包含数字4时,我们可以通过把4拆成322来变大,同理:

F(6) = F(53)

F(8) = F(7222)

F(9) = F(7332)

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6 int n,A[100];
 7 char str[20];
 8 int main()
 9 {
10     while(scanf("%d",&n)!=EOF)
11     {
12         scanf("%s",str);
13         int f = 0;
14         for(int i = 0;i < n;++i)
15         {
16             if(str[i] == '4')
17             {
18                 A[f++] = 3;
19                 A[f++] = 2;
20                 A[f++] = 2;
21             }
22             else if(str[i] == '6')
23             {
24                 A[f++] = 5;
25                 A[f++] = 3;
26             }
27             else if(str[i] == '8')
28             {
29                 A[f++] = 7;
30                 A[f++] = 2;
31                 A[f++] = 2;
32                 A[f++] = 2;
33             }
34             else if(str[i] == '9')
35             {
36                 A[f++] = 7;
37                 A[f++] = 3;
38                 A[f++] = 3;
39                 A[f++] = 2;
40             }
41             else
42             {
43                 if(str[i]-'0' > 1)
44                     A[f++] = str[i] - '0';
45             }
46         }
47         sort(A,A+f);
48         for(int i = f-1;i >= 0;--i)
49         printf("%d",A[i]);
50         puts("");
51     }
52     return 0;
53 }
View Code

 

转载于:https://www.cnblogs.com/xiaxiaosheng/p/4316233.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值