Programmer Written Exam: Ape Counseling Recruitment 2021 Programming Questions Collection and Sorting (8)

1. The little monkey is given a complete binary tree. The nodes in the tree are all positive integers. What is the sequence formed by sorting the boundary nodes of the complete binary tree in counterclockwise order from the root node? The boundary node is defined as the leftmost node of each layer, the leaf node and the rightmost node of each layer. (One node can only be counted once)
Input description:
Enter a positive integer N in the first line, expressed as the number of nodes in a complete binary tree (1<=N<= 1 0 6 10^6106 ).
Input N positive integers in the second line, which is expressed as the traversal sequence of the complete binary tree.
Output description:
output the sequence formed by sorting the boundary nodes of the complete binary tree in counterclockwise order from the root node, separated by spaces
Example:
Input:
5
1 2 3 4 5
Output:
1 2 4 5 3

2. The little monkey found a cylinder with numbers written on the side. Observing carefully, the side of the column was divided into several small grids with N rows and M columns, each with a number written on it. Can you help the little monkey find the largest submatrix on the side of the cylinder?
Input description:
Enter two numbers NM in the first line (1<=N<=100,1<=M<=1000) and the
next N lines, enter M numbers in each line.
Output description:
Please output the largest child on the side of the cylinder Matrix and
Example:
Input:
2 3
2 1 2
3 -2 4
Output:
11

3. Yuanbao is playing a number guessing game recently. Given a number n, it means that the answer is between 1 and n. You can guess one number each time, and the game wins, but if you guess wrong, you will spend the guessed number. And know whether you guessed the big or the small, but there are k chances to avoid this cost. Yuanbao wants to know at least how many gold coins must be prepared to ensure victory in the game.
Input description:
enter two positives separated by spaces Integer n,k.(n<=300,k<=20)
Output description:
output a positive integer to indicate the number of gold coins Xiao Ming needs to prepare.
Example 1:
Input:
3 1
Output:
0

Example 2:
Input:
3 0
Output:
2

Guess you like

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