Exam Preparation | 2021 CSP Entry Group Preliminary Test Questions and Analysis

Analysis of the 2021 CSP-J Preliminary Test Questions

1. Multiple choice questions

1.

Answer: D

Analysis: C language is process-oriented, and the other three items are object-oriented.

2.

Answer: B

Analysis: Common sense questions, the Turing Award is in the computer field.

Academy Award Film Awards

The five awards of the Nobel Prize include : Physics Prize, Chemistry Prize, Peace Prize, Physiology or Medicine Prize and Literature Prize

The Pulitzer Prize is the highest international award in journalism

3.

Answer: A

Analysis: The computer uses binary for storage.

4.

Answer: C

Analysis: Set the first number as max and compare it with the next n-1 numbers in turn and take the larger value. The number of comparisons is n-1.

5.

Answer: D

Analysis: After c and d are popped out of the stack, the elements in the stack from the bottom of the stack to the top of the stack are a, b, and the stacking order of a must be after b.

6.

Answer: D

Analysis: The number of edges of the tree is n-1, so m-(n-1) edges need to be deleted.

7.

Answer: C
Parsing:

8.

Answer: A

Analysis: The number of bottom nodes of a complete binary tree with a height of 5 is within [1, 16], so there are 16 different forms.

9.

Answer: B

Parsing: The postfix expression is in the form of two operands before the operator.

10.

Answer: B

Analysis: First calculate according to the "number to distinguish the teams", and then remove the arrangement of the three teams. C(6,2)×C(4,2)×C(2,2)÷A(3,3)=15

11.

Answer: B

Analysis: Huffman coding adopts a greedy strategy.

12

Answer: A

Analysis: Category Discussion:

· Put 3 in the first place, and put 1 or 2 in the last two places. There are 2×2=4 kinds;

If the last two digits are the same number, there are 2 schemes 3 11 3 22

If the last two digits are different numbers, there are two schemes A(2,2) 3 12 3 21

· Put 1 or 2 in the first digit, and choose the last two digits:

Put two different numbers, there are A(3,2)=6 kinds (1,2,3) choose two numbers

Put two identical numbers, there is 1 kind.

To sum up, there are 4+(6+1)×2=18 kinds in total.

13.

Answer: C

Analysis: Just calculate by hand: 7×5×3×2×1=210.

14.

Answer: B

Parsing: There are three possible traversal orders:

The first type: abdce

The second type: acdbe

The third type: acedb

Therefore, there are two possibilities for the last traversed point.

15.

Answer: B

Parse:

Greedy algorithm, in order to save time, let 4, 8 cross the river, 1, 2 sail from B to A.

One of the optimal solutions: 1, 2 cross the river, 1 return, 4, 8 cross the river, 2 return, 1, 2 cross the river. The total time-consuming is 2+1+8+2+2=15.

Typical misunderstanding: Let 1 be the boatman and the other three people cross the river, and it takes 8+1+4+1+2=16.

2. Reading procedure

(1)

Analysis: f(x) returns the number of 1s in x in binary representation, and g(x) returns the power of 2 corresponding to the lowest 1 in x in binary representation.

16.

Answer: F

Analysis: when n=1001, line 22 will perform cin>>a[1000]; while the subscript range of array a is [0, 999], subscript out of bounds will occur.

17.

Answer: F

Analysis: According to the function of the program, negative numbers and 0 will not cause the program to fall into an infinite loop.

18.

Answer: F

Analysis: For a[4]=(10)10=(1010)2, f(x)=2, g(x)=2, the output result in the title is 5, so it is wrong.

19.

Answer: T

Analysis: (511998) 10=(1111100111111111110) 2, calculate f(x)=16, g(x)=2, correct.

20.

Answer: F

Analysis: When calling g(a[i]) after moving, it will prompt that the g function is not declared and cannot be used in the main function.

21.

Answer: B

Analysis: From 65536=216, 2147483647=231-1:

(One 65536) The representation of 10 in binary is 16 1s followed by 16 0s,

(2147483647) 10 in binary is expressed as 1 0 followed by 31 1s, calculated as f(-65536)=16, g(65536)=65536, f(2147483647)=31, g(2147483647)=1.

(2)

Analysis: Decrypt the given string.

The encryption principle is to disassemble 3 characters (3×8=24 bits in total) into 4 small characters represented by 6 bits.

The decryption principle is to synthesize 4 characters into 3 large characters represented by 8 bits.

22.

Answer: F

Analysis: The title is described as the value range of small characters. This program performs the decryption process, and the output string can be composed of any characters.

table的有效下标是a-z,A-z,0’-9’,+,/,=,值是0-63。0-63进行decode里的各种位运算不一定还是a-z,A-z,'0'-9’,+,/,=(例如第27题有空格)

23.

答案:T

解析:程序仅对字母、数字、“+”、“/”、“=”这64种字符进行了区分,只有输入由a-z,A-z,0'-9’,+,/,=组成的字符串时,table的内容才会是0-63。其他所有字符都会被看作同一字符,table的值一律是0xff。因此输出很有可能相同。

24.

答案:T

解析:可以看到table的0号下标(或者看base的内容是0的位置),在上面的表格里不存在,因此table[0]是默认的0xff。因为这是8位的char,因此确实是-1。

1的源码00000001,反码11111110,补码1111111。负数是用补码存的。

25.

答案:B

解析:观察程序得,encode中只有一个O(n)的循环,循环内部为简单运算和string的+=操作。

26.

答案:B

解析:手算即可。

27.

答案:C

解析:根据输入字符串长度为12,末尾有1个“=”可知:输出字符串长度为8,故排除AB。CD选项的差别仅在最后一位,只需相应地根据输入字符串中的jE部分计算出最后一位即可。

(3)

分析:该代码是线性筛法,不仅仅只求了质数,还求出了f数组和g数组,题目中的f数组 求的是 每个数的约数的个数,g数组求的是约数的和

如果第一次看到这个程序,程序本身较难读懂,可以从2开始多找几个点算一算帮助理解。

28.

答案:T

解析:f[1],g[1]在x=1以外的情况下用不到。

29.

答案:F

解析:不会出现。c[i]记录的值为i的最小质因子的次数+1,即f[i]的一个因子。在f[i*k]=f[i]/c[i*k]*(c[i*k]+1)中,带入c[i*k]=c[i]+1得:f[i*k]=f[i]/(c[i]+1)*(c[i]+2),起到将f[i]中的因子c[i]+1替换为c[i]+2的效果,不会出现除不尽需要下取整的情况。

30.

答案:F

Analysis: You can simply find out the inverse example: g[4]=7, 9[5]=6.

31.

Answer: A

Analysis: inside the second layer of loop, a[i*k]=1 has the effect of sieving the composite number, and the composite number i×k will only be screened in this case (k is its smallest prime factor) Go (in other cases, such as i×k=i'×k', because k' is not the smallest prime factor, so it will break before the cycle of i' reaches k'), so the time complexity is (n) of.

32.

Answer: C

Analysis: f[i]=2 means that i is a prime number, and there are 25 prime numbers within 100.

33.

Answer: C

Analysis: 1000=23×53, so f[1000]=16, g[1000]=2340.

3. Improve the program

(1)

This question is a classic Joseph ring problem, and the difficulty is moderate. It focuses on thinking and requires logical analysis layer by layer.

34

Answer: D

Analysis: The variable c records the number of people leaving, and it needs to loop until c=n-1.

35.

Answer: C

Analysis: p records the number reported by the current person, and leaves if the reported number is 1.

36.

Answer: C

Parsing: Update the number of people leaving.

37.

Answer: D

Analysis: Report 0 or 1 alternately.

38.

Answer: B

Analysis: i represents the person who is currently reporting the number, so it should be circled from 0-(n-1).

(2)

Topic analysis: After reading through the program, I found that there is a binary_search in the topic, so I am looking for something. Observing lines 64 and 65, it is inferred that the loop here is enumerating any two points i, j, that is, enumerating any two points as two points on the diagonal of a rectangle, and then looking for two points on another diagonal to store does not exist.

39.

Answer: B

Parsing: Sort all points according to the horizontal and vertical coordinates. What is controversial is the D option. When the time is equal, it must be sorted according to the id. In the following binary search process, the coordinates of the two points are compared. If the coordinates of mid are small, they are searched for larger ones, so the sorting is also according to Coordinates are sorted from small to large

If you want to compare according to the coordinates, then the id of mid must be smaller than the id of p,

In extreme cases, if there are two elements, what to find is A[0], a = 0, b = 1

But it still returns true when comparing, a = mid+1=1, after the program ends, it is equivalent to skipping the answer directly. There is no answer.

40.

Answer: D

Analysis: The unique function has the effect of deleting redundant points. If the point is the first point, keep it. Otherwise, judge whether the coordinates of this point and the previous point are exactly the same. If so, discard it, otherwise keep it.

41.

Answer: C

Analysis: When looking for a smaller value, mid is assigned, so it is rounded down.

The calculation result of option A is wrong (such as a=3, b=4, mid=5).

When the amount of data is odd, BCD can be used. When the amount of data is even, the BD option may have a point selection error/enter an infinite loop.

42.

Answer: B

Analysis: The points are sorted in ascending order of coordinates (ie cmp(A[i], A[i+1])==1), and the same method is used for comparison when dividing: if cmp(A[mid], p) ==1, then point p must be on the right side of mid.

43.

Answer: D

Analysis: The points of the binary search in the following article are the upper left vertex and the lower right vertex of the rectangle, so the first two layers of loops have the effect of enumerating the lower left vertex and the upper right vertex to prevent repeated enumeration.

 If you have more questions, please add WeChat message consultation: mssg1992

Guess you like

Origin blog.csdn.net/Andy__cheng/article/details/126796692