您的位置:首页 > 其它

Codeforce 515C. Drazil and Factorial(字符串思维题)

2020-10-14 20:59 381 查看

【CodeForces】C. Drazil and Factorial

题目链接:Click Here

题意:找一个最大的数,使得每个位的阶乘的乘积与给定数相同。

首先將 2~9 轉成這樣(0,1為空):
2 -> 2 (2! = 2不能以其他方式組成)
3 -> 3 (3! = 6不能以其他方式組成)
4 -> 322 (4! = 24 可以用3! * 2! * 2! 組成)
5 -> 5 (5! = 120)
6 -> 53
7 -> 7
8 -> 7222
9 ->7332

只要想到这个就很简单了,利用字符串存储,去相应替代每一个即可

// Author : RioTian
// Time : 20/10/14
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, i, Fac[10] = {0, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};
string a[] = {"", "", "2", "3", "322", "5", "53", "7", "7222", "7332"};
string s, ss = "";
int main() {
// freopen("in.txt","r",stdin);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> s;
for (i = 0; i < n; ++i)
ss += a[s[i] - '0'];
sort(ss.rbegin(), ss.rend());
cout << ss << endl;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: