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


看看每一个数可以分解为哪些数 处理一遍就可以了
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN     freopen("input.txt","r",stdin);
#define FOUT    freopen("output.txt","w",stdout);
#define INF     0x3f3f3f3f
#define INFLL   0x3f3f3f3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;
typedef pair<int, int> PII;
using namespace std;

char ch[20];
int cnt[10];

int main() {
    //FIN
    int n;
    while(~scanf("%d", &n)) {
        memset(cnt, 0, sizeof(cnt));
        scanf("%s", ch);
        for(int i = 0; i < n; i++) cnt[ch[i] - '0']++;
        int tmp = cnt[9];
        cnt[3] += (tmp * 2);
        cnt[2] += tmp;
        cnt[7] += tmp;
        cnt[9] = 0;

        tmp = cnt[8];
        cnt[7] += tmp;
        cnt[2] += (tmp * 3);
        cnt[8] = 0;

        tmp = cnt[6];
        cnt[5] += tmp;
        cnt[3] += tmp;
        cnt[6] = 0;

        tmp = cnt[4];
        cnt[3] += tmp;
        cnt[2] += (tmp * 2);
        cnt[4] = 0;

        cnt[1] = 0;
        cnt[0] = 0;
        for(int i = 9; i >= 0; i--) {
            if(cnt[i] == 0) continue;
            for(int j = 1; j <= cnt[i]; j++) printf("%d", i);
        }
        printf("\n");

    }

    return 0;
}

  

转载于:https://www.cnblogs.com/Hyouka/p/7392484.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值