Codeforces Round #292 (Div. 2) C. Drazil and Factorial
2015-03-05 16:41
513 查看
题目链接: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)
View Code
给出一个公式例如: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)
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int n,A[100]; char str[20]; int main() { while(scanf("%d",&n)!=EOF) { scanf("%s",str); int f = 0; for(int i = 0;i < n;++i) { if(str[i] == '4') { A[f++] = 3; A[f++] = 2; A[f++] = 2; } else if(str[i] == '6') { A[f++] = 5; A[f++] = 3; } else if(str[i] == '8') { A[f++] = 7; A[f++] = 2; A[f++] = 2; A[f++] = 2; } else if(str[i] == '9') { A[f++] = 7; A[f++] = 3; A[f++] = 3; A[f++] = 2; } else { if(str[i]-'0' > 1) A[f++] = str[i] - '0'; } } sort(A,A+f); for(int i = f-1;i >= 0;--i) printf("%d",A[i]); puts(""); } return 0; }
View Code
相关文章推荐
- Codeforces Round #292 (Div. 2) -- C. Drazil and Factorial
- Codeforces Round #292 (Div. 2) C. Drazil and Factorial(贪心YY)
- Codeforces Round #292 (Div. 1)---A. Drazil and Factorial
- Codeforces Round #292 (Div. 2)——C——Drazil and Factorial
- Codeforces Round #292 (Div. 1)A. Drazil and Factorial 构造
- Codeforces Round #292 (Div. 2) C. Drazil and Factorial(贪心)
- Codeforces Round #292 (Div. 2) C. Drazil and Factorial(贪心)
- Codeforces Round #292 (Div. 1) C. Drazil and Park
- Codeforces Round #291 (Div. 1)B. Drazil and Tiles
- C. Drazil and Factorial
- Codeforces Round #292 (Div. 1) C. Drazil and Park 线段树
- Codeforces Round #292 (Div. 1) C. Drazil and Park 线段树
- CF Drazil and Factorial (打表)
- Codeforces Round #292 (Div. 1) B. Drazil and Tiles(拓扑排序)
- Codeforces Round #292 (Div. 2) D. Drazil and Tiles [拓扑排序 dfs]
- Codeforces Round #292 (Div. 2) C. Drazil and Factoria
- 【CodeForces】C. Drazil and Factorial
- Codeforces Round #292 (Div. 1) B. Drazil and Tiles (类似拓扑)
- C. Drazil and Factorial
- Codeforces Round #292 (Div. 2) -- D. Drazil and Tiles (拓扑排序)