51nod 1435 位数阶乘 (思维水题)


题目来源:  CodeForces
基准时间限制:1 秒 空间限制:131072 KB 分值: 40  难度:4级算法题
 收藏
 关注

X是一个n位数的正整数  (x=a0a1...an1)  

现在定义  F(x)=i=0n1(ai!)   , 比如F(135)=1!*3!*5!=720.

我们给定一个n位数的整数X(至少有一位数大于1,X中可能有前导0),

然后我们去找一个正整数(s)符合以下条件:

1.这个数尽可能大,

2.这个数中不能含有数字0或1。

3.F(s)=F(x)


Input
每个测试数据输入共2行。
第一行给出一个n,表示x为中数字的个数。(1<=n<=15)
第二行给出n位数的正整数X(X中至少有一位数大于1)
Output
共一行,表示符合上述条件的最大值。
Input示例
4
1234
Output示例
33222
System Message  (题目提供者)


思路:不知道为什么这题竟然是4级题, 一会就会了。。 能变成2,3的阶乘就变成2,3的阶乘, 而且2一定比3多, 5,7的阶乘都不能拆, 只能是自己....

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char s[20];
int cnt[20];
int main()
{
    int n;
    cin >> n;
    cin >> s;
    int len = strlen(s);
    for(int i = 0; i < len; i++)
    {
        if(s[i] == '0' || s[i] == '1') cnt[1]++;
        if(s[i] == '2') cnt[2]++;
        if(s[i] == '3') cnt[2]++, cnt[3]++;
        if(s[i] == '4') cnt[2]+=3, cnt[3]++;
        if(s[i] == '5') cnt[5]++;
        if(s[i] == '6') cnt[2]++, cnt[3]++, cnt[5]++;
        if(s[i] == '7') cnt[7]++;
        if(s[i] == '8') cnt[2]+=3, cnt[7]++;
        if(s[i] == '9') cnt[3]+=2, cnt[2]+=3, cnt[7]++;
    }
    cnt[2] -= cnt[3];
    for(int i = 7; i >= 2; i--)
    {
        if(cnt[i])
        {
            for(int j = 1; j <= cnt[i]; j++)
                printf("%d", i);
        }
    }
    return 0;
}


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值