Codeforces 515C. Drazil and Factorial

//codeforces 515C. Drazil and Factorial
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

/**
4!=2!*2!*3!
6!=1*2*3*4*5*6=5!*3!
8!=1*2*3*4*5*6*7*8=7!*2!*2!*2!
9!=1*2*3*4*5*6*7*8*9=7!*2!*3!*3!
*/

int main()
{
    char a[20];
    int ch[10] = {0};
    int n;
    cin >> n;
    cin >> a;
    for (int i = 0; i < n; ++i) {
        if (a[i] == ‘4‘) {
            ch[2] += 2;
            ++ch[3];
        } else if (a[i] == ‘6‘) {
            ++ch[3];
            ++ch[5];
        } else if (a[i] == ‘8‘) {
            ++ch[7];
            ch[2] += 3;
        } else if (a[i] == ‘9‘) {
            ++ch[7];
            ++ch[2];
            ch[3] += 2;
        } else if (a[i] == ‘0‘ || a[i] == ‘1‘) {
            continue;
        } else {
            ++ch[a[i] - ‘0‘];
        }
    }
    for (int i = 9; i >= 2; --i) {
        while (ch[i]) {
            putchar(i + ‘0‘);
            --ch[i];
        }
    }

    return 0;
}

  只是觉得很神奇的做法,但不太明白为什么……先记下来……

时间: 2024-12-14 10:46:51

Codeforces 515C. Drazil and Factorial的相关文章

codeforces 515C. Drazil and Factorial 解题报告

题目链接:http://codeforces.com/problemset/problem/515/C 题目意思:给出含有 n 个只有阿拉伯数字的字符串a(可能会有前导0),设定函数F(a) = 每个数字的阶乘乘积.例如 F(135) = 1! * 3! * 5! .需要找出 x,使得F(x) = F(a),且组成 x 的数字中没有0和1.求最大的 x 为多少. 这个我是看了每个数字的转换才知道怎么做的. 0, 1     —— >  empty(用空串表示) 2         —— > 

Codeforces Round #292 (Div. 2) C. Drazil and Factorial 515C

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 dig

Codeforces Round #292 (Div. 1)---A. Drazil and Factorial

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 n

[codeforces 516]A. Drazil and Factorial

试题描述 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.

【CodeForces】C. Drazil and Factorial

Problem here Problem 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 la

codeforces 515B.Drazil and His Happy Friends

B. Drazil and His Happy Friends time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his f

codeforces 515B. Drazil and His Happy Friends 解题报告

题目链接:http://codeforces.com/problemset/problem/515/B 题目意思:有 n 个 boy 和 m 个 girl,有 b 个 boy 和 g 个 girl (通过给出数组下标)是 happy的,规定每轮 dinner 中,派出编号为 i mod n 个男 和 i mod m 个女去.只要他们其中一个为 happy 时,另一个也会变得 happy,问最终所有男女是否都变得 happy. 一步一步模拟就可以了.这个问题有一个难点,就是究竟要进行多少次才能判断

codeforces 515A.Drazil and Date 解题报告

题目链接:http://codeforces.com/problemset/problem/515/A 题目意思:问能否从 (0, 0) 出发,恰好走 s 步,到达该位置(a, b). 首先容易知道,最少的步数为 |a| + |b|,最长就是——当然是无限啦(乱兜圈子就行).然后就有一点点带着个人感觉来做了= =,第六感确实不错的,呵呵,证明就有待考究了. 如果 |a| + |b| 跟 s 的奇偶性相同就有解,否则无解.当然前提是满足 s 至少要比最少的步数大! 1 #include <iost

Codeforces 516D Drazil and Morning Exercise (栈、二分)

题目链接 https://codeforces.com/contest/516/problem/D 题解 我还是数据结构水平太低了啊--连一个点子树内距离不超过\(l\)的点数都不会求 首先有一个熟知的结论是,我们任取原树的一条直径,那么对于任何一个点,直径的两端点中至少有一个到它的距离等于它到所有点的最远距离. 假设直径是\((u_d,v_d)\), 那么我们就把\(u\)的最远距离的式子化简成了\(f_u=\max(dis(u,u_d),dis(u,v_d)\). 考虑\(u_d\)和\(v