#P8788. [蓝桥杯 2022 国 A] 填空问题

[蓝桥杯 2022 国 A] 填空问题

Problem Description

Problem A: Xiao Lan and the Keys

Problem Description

Xiao Lan is a kindergarten teacher. There are 2828 children in his class, and today he played a game with them.

Xiao Lan’s school is a boarding school. Each of the 2828 children has their own room, and each room corresponds to one key. Each key can only open its own door. Now Xiao Lan asks these 2828 children to hand in their dorm room keys, then he randomly shuffles the 2828 keys and gives one key to each child. There are 28!=28×27××128 != 28 \times 27 \times \cdots \times 1 possible assignment schemes. Xiao Lan wants to know: among these schemes, how many schemes have exactly half of the children receiving the key to their own room (that is, 1414 children receive their own room key, and 1414 children do not).

Answer Submission

This is a fill-in-the-blank result problem. You only need to compute the result and submit it. The result of this problem is an integer. When submitting the answer, only fill in this integer; any extra content will make you unable to get points.

Problem B: Permutation Distance

Problem Description

Xiao Lan has recently become obsessed with full permutations. Now he has a permutation of length 1717, containing the elements: abcdefghijklnopqr, i.e., all lowercase letters from a to rr except m\mathrm{m}. Each of these 1717 letters appears exactly once in any permutation. The first few permutations in order are:

The 11st permutation is: abcdefghijklnopqr;

The 22nd permutation is: abcdefghijklnoprq;

The 33rd permutation is: abcdefghijklnoqpr;

The 44th permutation is: abcdefghijklnoqrp;

The 55th permutation is: abcdefghijklnorpq;

The 66th permutation is: abcdefghijklnorqp;

The 77th permutation is: abcdefghijklnpogr;

The 88th permutation is: abcdefghijklnporq;

The 99th permutation is: abcdefghijklnpqor;

The 1010th permutation is: abcdefghijklnpqro.

For a permutation, there are two transition operations:

  1. Transition to its next permutation. If the current permutation is already the last permutation, then the next permutation is the first permutation.

  2. Transition to its previous permutation. If the current permutation is the first permutation, then the previous permutation is the last permutation.

Now Xiao Lan has two permutations: permutation A:A: aejcldbhpiogfqnkr, and permutation B:B: ncfjboqiealh krpgd. He wants to know: under the constraint that only the two transition operations above are allowed, what is the minimum number of transitions needed to transform permutation AA into permutation BB.

Answer Submission

This is a fill-in-the-blank result problem. You only need to compute the result and submit it. The result of this problem is an integer. When submitting the answer, only fill in this integer; any extra content will make you unable to get points.

Input Format

The input contains one uppercase letter, indicating which problem it is.

Output Format

According to the input problem label, output the corresponding answer to that problem.

Hint

Answer template, for reference.

#include<iostream>
using namespace std;
int main() {
    string ans [] = {
        "The answer of task A", // 双引号中替换为 A 题的答案
        "The answer of task B", // 双引号中替换为 B 题的答案
    };
    char T;
    cin >> T;
    cout << ans[T - 'A'] << endl;
    return 0;
}

Translated by ChatGPT 5