• CF292-C


    C. Drazil and Factorial
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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 test(s)
    input
    4
    1234
    output
    33222
    input
    3
    555
    output
    555
    Note

    In the first case, 

    自己先意淫2!~9!能被何数给表示(尽可能的使位数多)

    可以发现

    F(2)=F(2)

    F(3)=F(3)

    F(4)=F(322)

    F(5)=F(5)

    F(6)=F(53)

    F(7)=F(7)

    F(8)=F(7222)

    F(9)=F(7332)

     转换后将所有数排序输出即可。。比赛时大意地认为F(9)=F(733222),结果被hack,直降1000名。。。以后要格外认真才行

    #include <iostream>
    #include <string.h>
    using namespace std;
    char res[20];
    
    int main()
    {
        int a[10];
        int b[10];
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        int n;
        cin>>n;
        cin>>res;
        for(int i=0;i<strlen(res);i++)
        {
            a[res[i]-'0']++;
        }
        for(int i=0;i<=9;i++)
        {
            if(a[i]!=0)
            {
                switch (i)
                {
                case 2:
                    b[2]+=a[i];
                    break;
                case 3:
                    b[3]+=a[i];
                    break;
                case 4:
                    b[2]+=2*a[i];
                    b[3]+=a[i];
                    break;
                case 5:
                    b[5]+=a[i];
                    break;
                case 6:
                    b[5]+=a[i];
                    b[3]+=a[i];
                    break;
                case 7:
                    b[7]+=a[i];
                    break;
                case 8:
                    b[7]+=a[i];
                    b[2]+=3*a[i];
                    break;
                case 9:
                    b[7]+=a[i];
                    b[3]+=2*a[i];
                    b[2]+=a[i];
                    break;
                }
            }
        }
        for(int i=9;i>=2;i--)
        {
            while (b[i])
            {
                cout<<i;
                b[i]--;
            }
        }
        cout<<endl;
        return 0;
    }
    
    
  • 相关阅读:
    sql limit 的用法
    浅谈XSS攻击
    python dns 服务器
    简单的文件上传下载服务器
    Linux下pyftplib简单的脚本
    浅谈optparse 解析命令行参数库
    爬虫下载脚本
    python 递归算阶乘 (转载)
    遍历目录及其子目录的文件
    Oracle数据导入导出
  • 原文地址:https://www.cnblogs.com/wzsblogs/p/4295808.html
Copyright © 2020-2023  润新知