#P8788. [蓝桥杯 2022 国 A] 填空问题
[蓝桥杯 2022 国 A] 填空问题
Problem Description
Problem A: Xiao Lan and the Keys
Problem Description
Xiao Lan is a kindergarten teacher. There are children in his class, and today he played a game with them.
Xiao Lan’s school is a boarding school. Each of the 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 children to hand in their dorm room keys, then he randomly shuffles the keys and gives one key to each child. There are 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, children receive their own room key, and 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 , containing the elements: abcdefghijklnopqr, i.e., all lowercase letters from a to except . Each of these letters appears exactly once in any permutation. The first few permutations in order are:
The st permutation is: abcdefghijklnopqr;
The nd permutation is: abcdefghijklnoprq;
The rd permutation is: abcdefghijklnoqpr;
The th permutation is: abcdefghijklnoqrp;
The th permutation is: abcdefghijklnorpq;
The th permutation is: abcdefghijklnorqp;
The th permutation is: abcdefghijklnpogr;
The th permutation is: abcdefghijklnporq;
The th permutation is: abcdefghijklnpqor;
The th permutation is: abcdefghijklnpqro.
For a permutation, there are two transition operations:
-
Transition to its next permutation. If the current permutation is already the last permutation, then the next permutation is the first permutation.
-
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 aejcldbhpiogfqnkr, and permutation 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 into permutation .
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