Programmer Written Exam: Tencent 2021 Campus Recruitment Backstage & Comprehensive Programming Questions Collection (11)

1. Little Q gives you two linked lists sorted in descending order. Little Q hopes you can find the common part of the two linked lists. The common part refers to the subsequences that have appeared in both linked lists.
Note: You need to process the input and output yourself, please define it yourself according to the meaning of the question, linked list nodes, related functions
Input description:
the first line of input is the length of the first linked list n. The
second line is the value val of each node of the first linked list.
The third line is the length of the second linked list, m. The
fourth line is the value of each node of the second linked list va.
1<=n, m<=1000000, − 1 0 9 <= val <= 1 0 9 -10^ 9<=val<=10^9109<=val<=109
Output description:
output a row of integers in descending order, representing the value of the common part of two ascending linked lists.
Example input:
6
6 5 4 3 2 1
5
6 5 3 2 1
Example output:
6 5 3 2 1

2. Little Q manages a large team, there are n people in the big team, m small teams, you know the number of people in each small team and the number of each person (number range is 0~n-1, one person may Belongs to multiple small teams, and some people may not belong to a small team.) Now Xiao Q will issue a notification to the person numbered 0, and all people who belong to a small group with the person numbered 0 will pass the number People with 0 know this notification, and those who know the notification will then send the notification to other people in their small team. Now ask you how many people in total are aware of the notification (including the person with the number 0).
Input description:
Enter the two numbers n and m in the first line, which means there are n people, m small teams
followed by m lines, and the first number in each line first enter an x, which means this small team has x people, followed by x Number, representing the number of people in this small team
1<=n<=100000
1<=m<=500
1<=x<=100
Output description:
For each set of test data, please output an answer to represent the notification Number of people.
Example input:
50 5
2 1 2
5 10 11 12 13 14
2 0 1
2 49 2
4 6 7 8 2
Example output:
7

3. Little Q gives you N strings. Little Q hopes that you can count the number of occurrences before k and the first k less (the number of occurrences cannot be 0).
Note: The explanation of the lexicographic order of strings:
1. The lexicographic order follows the character-by-character comparison method, the more left characters are compared first;
2. In the character-by-character comparison process, once a pair is found to be compared When the characters are not equal, the size relationship of the pair of characters is the size relationship of the pair of character strings;
3. In the process of character-by-character comparison, once all characters of a character string have been compared, and the other When there are uncompared characters in the string, the shorter string is smaller.
eg. "abc"<"abd"
eg. "abc"<"abcde"
Input description:
the first line of input is two integers N, K. The
next N lines, each line is a string.
1<=N<= 1 0 5 10^5105 , the sum of string length <=1 0 5 10^5105,1<=K<= 1 0 5 10^5 105
Ensure that K is legal, and there are only numbers and English letters in the string.
Output description:
output 2*K lines, each line contains a string and the number of occurrences of the string.
The first K lines output the first K, you need to output according to the number of occurrences from large to small. If the number of occurrences is the same, the string with the smaller dictionary order will
be output first. The next K lines output the first K, you need to follow the number of occurrences from small to large Output, if the number of occurrences is the same, the string with the smaller dictionary order is preferred.
Example input:
4 2
1
1
2
3
Example output:
1 2
2 1
2 1
3 1

4. Give n numbers a1, a2,..., an, where n is an even number.
After deleting each number individually, what is the median of the remaining n-1 elements.
Input description: the
first line, an even number n (n<=200000), the
second line, enter n numbers, the i-th number represents ai, ai is in the range of 32-bit integers.
Output description:
output n rows, the i-th row indicates what is the median of the remaining n-1 elements after deleting the answer to ai
Example input:
6
1 2 3 4 5 6
Example output:
4
4
4
3
3
3

5. Little Q invented a new board game: red and black chess.
This game now has 2n chess pieces arranged in a row, among which there are n black chess pieces, numbered 1~n, and n red chess pieces, numbered 1~n.
Now little Q performs the following operations several times: swap phase Neighbor's pawn.
Now give the color and number of each piece. Little Q hopes that you can use the least number of operations to make the number of red pieces increase from left to right, and the numbers of black pieces increase from left to right. The color is not necessarily continuous.
Please find the minimum number of times you need.
Input description: The
first line outputs a number n (1<=n<=3000). The
second line includes a character string, that is, the colors of the 2n pieces in sequence.'R' represents red pieces, and'B' represents black pieces.
The third line contains 2n numbers separated by spaces, that is, the sequential numbers of these 2n pieces.
Output description:
output an integer to indicate the minimum number of operations
Example input:
3
BRRBRB
2 3 1 1 2 3
Example output:
5
Description:
Initial:
BRRBRB
231123
First exchange:
BRRBRB
213123
Second exchange:
BRBRRB
211323
Third exchange:
BRBRRB
211233
Fourth exchange:
BBRRRB
211233
Fifth exchange:
BBRRRB
121233

Guess you like

Origin blog.csdn.net/qq_34124009/article/details/108441744