Programmer Written Exam: Pinduoduo 2021 Campus Recruitment Test Development Engineer Programming Questions Collection (10)

1. Duoduo is so boring in the hot summer, only studying can maintain inner peace. Duoduo is learning matrix knowledge recently, but he encountered a strange kind of matrix. So I want to print out the matrix and observe it carefully. For an n-order matrix, first divide the matrix into 8 regions with a m-shaped dividing line, and then start from the upper right corner and number the regions as 1, 2, ..., 8 in counterclockwise order. As shown in the figure:
Insert picture description here
At the same time, the matrix elements need to meet:
1) The elements in each area are equal to the number of the area.
2) The value of the element crossed by the dividing line is equal to 0.
I hope you can help him to print out this matrix.
Input description:
a number n, indicates the order of the matrix
(3<n<200).
Output description:
output n rows, n numbers in each row, separated by spaces to indicate the printed matrix
Example 1:
Input:
4
Output:
0 2 1 0
3 0 0 8
4 0 0 7
0 5 6 0

Example 2:
Input:
5
Output:
0 2 0 1 0
3 0 0 0 8
0 0 0 0 0
4 0 0 0 7
0 5 0 6 0

2. On a magical day, Duoduo came to a magical store with a magical backpack, and there were N magical goods in the store. The store manager asked Duoduo to pick any item into the backpack to take away. A lot of discovery, some of these products will take up a part of the backpack space, but some products will make the backpack bigger. At the same time, some of these commodities have certain returns, but some of them have negative returns. Duoduo would like to know what the biggest gain it can take away today.
For the top 60% of the data, the backpack space occupied by the goods and the income of the goods are both non-negative integers!
Input description: The
first line is two integers N, M, where N represents the total number of products, and M represents the original size of Duoduo's backpack.
There are two numbers in each row from 2 to N+1, Ci, Vi, where Ci represents the backpack space occupied by the i-th product. If Ci is a negative number, it means this product will increase the backpack space; Vi represents the i-th product's space income.
For 100% of the test data, satisfy:
1<=N<=200
0<=M<=5000
-100<=Ci<=100
-100<=Vi<=100
Output description: Example
of the maximum benefit that Duoduo can take away
:
Input:
4 4
-1 -1
1 -1
-1 1
6 6
Output:
6

3. Duo Duojun
is currently studying a new set of functions: Duo Duojun believes that if a positive integer X is divisible by a certain number Y in the eigenvalue set, then this positive integer X has significant characteristics. For a given N and M, where N represents a set of positive integers 1 ~ N, and M represents a set composed of M eigenvalues, Duo Duo Jun wants to know how many numbers have significant characteristics in the positive integers 1 ~ N .
Input description: The
first line, two positive integers N and M, respectively represent the size of the set of positive integers and the feature set.
(1<=N<=1,000,000,000,1<=M<=10)
Write down M rows, which represent the numbers of the feature set, where the i-th row represents the i-th feature value Yi.
Example 1:
Input:
10 2
2
3
Output :
7

Example 2:
Input:
10 3
2
3
5
Output:
8

Guess you like

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