zoukankan      html  css  js  c++  java
  • Codeforces Round #292 (Div. 2) C. Drazil and Factorial

    题目链接:http://codeforces.com/contest/515/problem/C

    给出一个公式例如:F(135) = 1! * 3! * 5!;

    现在给你一个有n位的数字a,让你求这样一个x,满足x中没有0和1,F(a) = F(x),然后就是x要最大.

    当x的位数比a多或者从高位开始x的数某一位要大于a的某一位,然后第二种显然是不可能的,所以我们寻找如何把a变长的方法.

    例如数字

    4! = 1 * 2 * 3 * 4

        =3! * 2 * 2

        =3! * 2! * 2!

    所以当a中包含数字4时,我们可以通过把4拆成322来变大,同理:

    F(6) = F(53)

    F(8) = F(7222)

    F(9) = F(7332)

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<algorithm>
     5 using namespace std;
     6 int n,A[100];
     7 char str[20];
     8 int main()
     9 {
    10     while(scanf("%d",&n)!=EOF)
    11     {
    12         scanf("%s",str);
    13         int f = 0;
    14         for(int i = 0;i < n;++i)
    15         {
    16             if(str[i] == '4')
    17             {
    18                 A[f++] = 3;
    19                 A[f++] = 2;
    20                 A[f++] = 2;
    21             }
    22             else if(str[i] == '6')
    23             {
    24                 A[f++] = 5;
    25                 A[f++] = 3;
    26             }
    27             else if(str[i] == '8')
    28             {
    29                 A[f++] = 7;
    30                 A[f++] = 2;
    31                 A[f++] = 2;
    32                 A[f++] = 2;
    33             }
    34             else if(str[i] == '9')
    35             {
    36                 A[f++] = 7;
    37                 A[f++] = 3;
    38                 A[f++] = 3;
    39                 A[f++] = 2;
    40             }
    41             else
    42             {
    43                 if(str[i]-'0' > 1)
    44                     A[f++] = str[i] - '0';
    45             }
    46         }
    47         sort(A,A+f);
    48         for(int i = f-1;i >= 0;--i)
    49         printf("%d",A[i]);
    50         puts("");
    51     }
    52     return 0;
    53 }
    View Code
  • 相关阅读:
    A*算法研究
    C++实现动态数组
    Sublime Text3括号配对与代码包围效果BracketHighlighter
    SublimeREPL配置Python3开发
    Ubuntu16.04下使用sublime text3搭建Python IDE
    Netbeans使用笔记
    vscode: Visual Studio Code 常用快捷键
    OKR 第一阶段
    浏览器是如何工作的
    javascriptdocument load 和document ready的区别
  • 原文地址:https://www.cnblogs.com/xiaxiaosheng/p/4316233.html
Copyright © 2011-2022 走看看