Codeforces Round #292 (Div. 2) C. Drazil and Factorial(贪心)
Description
Drazil is playing a math game with Varda.
Let's define for positive integer x as a product of factorials of its digits. For example, .
First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:
1. x doesn't contain neither digit 0 nor digit 1.
2. = .
Help friends find such number.
Input
The first line contains an integer n (1 ≤ n ≤ 15) — the number of digits in a.
The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
Output
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
Sample Input
4
1234
3
555
Sample Output
33222
555
Note
In the first case,
思路
题解:
处理前导0后,把每一个数字尽可能多的拆成其他数字的组合。
#include<bits/stdc++.h> using namespace std; const int maxn = 20; char s[maxn]; int a[maxn<<2]; bool cmp(int x,int y) { return x > y; } int main() { int n; scanf("%d",&n); scanf("%s",s); int index = 0,tot = 0; while (s[index] == '0') index++; for (int i = index;i <= n;i++) { if (s[i] == '0') continue; if (s[i] == '1') continue; if (s[i] == '2') a[tot++] = 2; if (s[i] == '3') a[tot++] = 3; if (s[i] == '4') a[tot++] = 3,a[tot++] = 2,a[tot++] = 2; if (s[i] == '5') a[tot++] = 5; if (s[i] == '6') a[tot++] = 5,a[tot++] = 3; if (s[i] == '7') a[tot++] = 7; if (s[i] == '8') a[tot++] = 7,a[tot++] = 2,a[tot++] = 2,a[tot++] = 2; if (s[i] == '9') a[tot++] = 2,a[tot++] = 3,a[tot++] = 3,a[tot++] = 7; } sort(a,a+tot,cmp); for (int i = 0;i < tot;i++) printf("%d",a[i]); printf("\n"); return 0; }
import java.util.Arrays; import java.util.Scanner; import static java.lang.System.out; public class DrazilAndFactorial { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); scan.nextLine(); String s = scan.nextLine(); s = s.replaceAll("0", ""); s = s.replaceAll("1", ""); s = s.replaceAll("4", "223"); s = s.replaceAll("6", "53"); s = s.replaceAll("8", "7222"); s = s.replaceAll("9", "7332"); char[] c = s.toCharArray(); Arrays.sort(c); for (int i = 0;i < c.length;i++) { out.print(c[c.length-1-i]); } out.println(); } }
- Codeforces Round #292 (Div. 2) C. Drazil and Factorial(贪心YY)
- Codeforces Round #292 (Div. 2) C. Drazil and Factorial(贪心)
- codeforces 515C C. 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)---A. Drazil and Factorial
- Codeforces Round #292 (Div. 1)A. Drazil and Factorial 构造
- Codeforces Round #292 (Div. 2) -- C. Drazil and Factorial
- Codeforces Round #370 (Div. 2)C. Memory and De-Evolution 贪心
- 贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks
- C. Drazil and Factorial
- codeforces#292-C - Drazil and Factorial-数学规律题
- Codeforces Round #353 (Div. 2)E. Trains and Statistic(ST表+贪心)
- Codeforces Round #277.5 (Div. 2)C. Given Length and Sum of Digits...(贪心)
- 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know
- Codeforces Round #245 (Div. 2) A. Points and Segments (easy) 贪心
- Codeforces Round #444 (Div. 2) D. Ratings and Reality Shows 贪心
- Codeforces Round #331 (Div. 2) B. Wilbur and Array (贪心)
- 【Codeforces Round #373 (Div. 2) 】【贪心】B. Anatoly and Cockroaches
- Codeforces Round #383 (Div. 1) C. Arpa’s overnight party and Mehrdad’s silent entering(贪心,二分图)