# `CSP_J_2021` first round of certification questions

1. Multiple Choice Questions

1. Which of the following is not an object-oriented programming language ( )

A. C++ B. Python C. Java D. C

2. Which of the following awards is most relevant to the computer field is ( ).

A. Oscar B. Turing Award C. Nobel Prize D. Pulitzer Prize

3. The current mainstream computer storage data is finally converted into ( ) data for storage.

A. Binary B. Decimal C. Octal D. Hexadecimal

4. Use comparison as the basic operation to find the largest number among N numbers. The minimum number of comparisons required in the worst case is ( )

A. N2 B.N C.N-1 D.N+1

5. For a,b,c,d,ethe sequence whose stacking sequence is , the following ( ) is not a legal stacking sequence.

A. a,b,c,d,e B. e,d,c,b,a C. b,a,c,d,e D. c,d,a,e,b

6. For an undirected connected graph (m>n) with nvertices and edges, it is necessary to delete ( ) edges to make it a tree.m

A.n-1 B.m-n C.m-n-1 D. m-n+1

7. Binary number 11.11The corresponding decimal number is ( )

A.6.5 B.5.5 C.5.75 D.5.25

8. If a binary tree has only a root node, then the height of the binary tree is 1. Does a complete binary tree of height 5have ( ) different shapes?

A.16 B. 15 C.17 D.32

9. a*(b+c)*dThe suffix expression of the expression is ( ), where *and +are operators.

A.**a+bcd B.abc+*d* C.abc+d** D.*a*+bcd

10. 6 people, two people form a team, a total of three teams, regardless of team number. There are ( ) kinds of different team formation situations.

A.10 B15 C.30 D.20

11. The Huffman coding method in data compression coding is essentially a ( ) strategy

A. Enumeration B. Greedy C. Recursion D. Dynamic programming

12. 1,1,2,2,3There are ( ) kinds of three-digit numbers composed of these five numbers.

A.18 B.15 C.12 D.24

13. Consider the following recursive algorithm, solve(7)the return result of the call is ( ).

solve(n)
if n<=1 return 1
else if n>=5 return n*solve(n-2)
else return n*solve(n-1)

A.105 B.840 C.210 D.420

14. Taking aas the starting point, perform a depth-first traversal on the undirected graph on the right, then b、 c、 d、 ethe number of points that may be the last to be traversed among the four points is ( ).

A.1 8.2 C.3 D.4

insert image description here

15. There are four people who want to take a boat from point A to cross the river to point B. The boat is at point A at first. The boat can seat up to two people at a time. It is known that the crossing time of each of these four people by boat alone is 1, 2, 4, and 8 respectively, and the time for two people to cross the river by boat is the larger of the time for two people to cross the river alone. Then the shortest ( ) time allows all four people to cross the river to point B (including the time to drive the boat back to point A from point B)

A.14 B15 C.16 D.17

2. Reading order

(1)

01 #include <iostream>
02 using namespace std;
03
04 int n;
65 int a[1088];
06
07 int f(int x)
08 {
09 	int ret=0; 
10 	for (;x; x &= x - 1) ret++;
11   return ret;
12 }
13
14 	int g(int x)
15	{
16   return x & -x;
17	}
18
19 int main()
20 { cin >> n;
22   for (int i =0;i < n; i++) cin >> a[i];
23   for (inti=0;i< n; i++)
24		cout << f(a[i]) + g(a[i]) <<'';
25    cout << endl;
26    return 0;

True or False

  1. When the input nis equal to 1001, the program will not cause the subscript to go out of bounds. ( )

  2. The input a[i]must be all positive integers, otherwise the program will fall into an infinite loop. ( )

  3. When the input 5 2 11 9 16 10is , the output is 3 4 3 1 7 5. ( )

  4. When the input 1 511998is , the output is "18". ( )

  5. gMove the function definition (lines 14-17) behind the main function in the source code , and the program can be compiled and run normally. ( )

multiple choice

  1. When the input 2 -65536 2147483647is , the output is ( ).

    A、65532 33 B、65554 33 C、65535 34 D、65554 33

(2)

01 #include <iostream>
02 #include <string>
03 using namespace std;
04
05 char base[64];
06 char table[256];
07
08 void init()
09 {
10     for (int i = 0;i< 26;i++) base[i] ='A'+ i;
11     for (int i= 0; i<26;i++) base[26 + i]='a'+ i;
12     for (int i =0;i< 10; i++) base[52 + i] ='0'+ i;
13     base[62]='+',base[63] ='/;
14
15     for (int i=0;i< 256; i++) table[i] = 0xff;
16     for (int i=0;i< 64; i++) table[base[i]] = i;
17     table['=']= 0;
18 }
19
20 string decode(string str)
21 {
22	string ret;
23  int i;
24  for (i=0;i < str.size(); i += 4){
25    ret += table[str[i]] << 2 | table[str[i + 1]] >> 4;
26    if (str[i + 2] !='=')
27         ret += (table[str[i + 1]] & 0x0f) << 4 | table[str[i +2]] >> 2;
28    if (str[ + 3] !='=')
29         ret += table[str[i + 2]] << 6 | table[str[i + 3]];
30 }
31 return ret;
32 }
33
34 int main()
35 (
36  init();
37  cout << int(table[e]) << endl;
38
39  string str;
40  cin >> str;
41  cout << decode(str) << endl;
42  return 0;
43 }

True or False

  1. The second line of output must be a string composed of lowercase letters, uppercase letters, numbers and "+", "/", and "=". ()
  2. There may be situations where the input is different, but the second line of output is the same. ( )
  3. The first line of output is "-1". ( )

multiple choice

25. Suppose the length of the input string is n, and decodethe time complexity of the function is ( ).

​ A. O(n开平方) B. O(n) C.O(nlogn) D、O(n2)

  1. When the input Y3Nxis , the second line of output is ( ).

    A. "csp" B、"csq" C、"CSP" D、"Csp"

  2. (3.5 points) When the input “Y2NmIDIWMjE=”is , the second behavior of the output is ( )

    A、"ccf2822”" B、ccf2022 C、ccf 2021 D、ccf 2022

(3)

01 #include <iostream>
02 using namespace std;
03
04 const int n = 100000;
05 const int N = n + 1;
06
07 int m;
08 int a[N],b[N],c[N],d[N];
09 int f[N],g[N];
10
11 void init()
12 {
13   f[1]= g[1]=1;
14   for (int i= 2;i <=n;i++){
15        if (!a[i]){
16            b[m++] =i;
17              c[i]= 1,f[i]=2;
18              d[i]= 1,g[i]=i+1; 
19  }
20    for (int j= 0;j< m && b[j]*i<= n; j++){
21    	 int k m b[j];	
22          a[i*k]=1;
23         if (i% k == 0) {
24             c[i* k]= c[i]+ 1;
25             f[i*k]=f[i] / c[i*k] * (c[i*k]+1);
26    		  d[i*k]= d[i];
27              g[i*k]=g[i]*k+d[i];
28              break;
29          }
30         else {
31			c[i*k]=1;
32			f[i*k]=2*f[i];
33			d[i*k]= g[i];
34			g[i*k]=g[i]*(k+1);
35       }
36     }
37   }
38 }
39
40  int main()
41 {
42   init();
43
44   int x;
45   cin >> x;
46   cout << f[x] <<'  '<< g[x] << endl;
47	return 0;
48 }

Assuming that the input x is a natural number not exceeding 1000, complete the following break and radio selection

True or False

28. If the input is not "1", deleting line 13 will not affect the output result. ( )

29. The number in the ( 2cent) line may not be divisible and rounded down.25“f[i] / c[ i* k]”

  1. (2 points) init()After , the f array is not monotonically increasing, but the g array is monotonically increasing.

multiple choice

31. initThe time complexity of the function is ( ).
A. O(n)B. O(nlogn)C. O(n根号n) D. O(n 2 )

  1. init()After execution , f[1],f[2],f[3] .. f[100]there are ( ) equal to 2

    A.23 B.24 C25 D.26

33. (4 points) When the input is "1000", the output is ( )

A 、15 1340 B.15 2340 C16 2340 D16 1340

3. Improve the program

(1) (Josephus problem) There are npeople forming a circle, marking 0from to n-1number 0in turn, and 0,1,0,1,...counting alternately in turn, and 1those who report will leave until there is only one person left in the circle. Find the number of the last remaining person.
Try to complete the simulation program.

01 #include <iostream>
02
03 using namespace std;
04
05 const int MAXN = 1000000;
06 int F[MAXN];
07
08 int main() (
09 int n;
10 cin >> n;
11 int i=0,p=0,c=0;
12 while (  1  ){
13   if ( F[i] == 0){
14     if( 2 ){
15         F[i] = 1;
16         3
17       }
18         4
19      }
20      5
21 }
22  int ans = -1;
23  for (i=0;1<n;i++)
24     if (F[i]==0)
25         ans = i;
26    cout << ans << endl;
27     return 0; 
28 }
  1. 1should fill in ( )

A、i<n B c<n C i<n-1 D c<n-1

  1. 2 should ( )

A、i % 2==0 B、i%2==1 C、 p D、!p

  1. 3should fill in ( )

A、i++ B、i=(i+1)%n C、c++ D、p^=1

  1. 4should fill in ( )

A、i++ B、i=(i+1)%n C、c++ D、p^=1

  1. 5should fill in ( )
    A、i++ B、i=(i+1)%n C、c++ D、p^=1

(2)
(rectangle count) There is a key point on the plane n, find how many rectangles whose four sides are parallel to xthe axis or the axis, satisfying that the four vertices are all key points. yThe given keypoints may have repetitions, but completely coincident rectangles are counted only once.
Try to complete the enumeration algorithm.

01 #include <iostream>
02
03 using namespace std;
04
05 struct point {
06		int x,y, id;
07 };
08
09 bool equals(point a, point b) {
10		return a.x == b.x && a.y == b.y;
11 }
12
13 bool cmp(point a,point b) {
14	return 1;
15 }
16
17 void sort(point A[],int n) {
18		for (int i=;i<n; i++)
19			for (int j= 1;j< n;j++)
20				if (cmp(A[j],A[j - 1])){
21					point t = A[j];
22					A[j] = A[j- 1]
23					A[j-1] =t;
24		}
25	}
26
27 int unique(point A[],int n) {
28		int t =0;
29		for (int i =0;i < n; i++)
30           if(2)
31				A[t++]A[i];
32		return t;
33 }
34
35 bool binary_search(point A[],int n,int xint y) {
36		point p;	
37		p.X = X;
38		p.y = y;
39		p.id =n;
40		int a=0,b=n- 1;
41		while (a < b) {
42		    int mid = 3;
43			if( 4 )
44				a = mid + 1;
45			else
46				b = mid;
46
47       }
48	return equals(A[a],p);
49 }
50
51 const int MAXN = 100;
52 point A[MAXN];
53
54 int main() {
55		int n;
56		cin >> n;
57		for (int i=0;i < n; i++) {
58			cin >> A[1].x >> A[i].y;
59           A[i].id = i;
60  }
61	sort(A,n);
62	n = unique(A,n);
63	int ans = 0;
64	for (int i=0 ;i< n;i++)
65		for (int j= 0;j< n; j++)
66			if (5  && binary_search(A,n,A[i].x,A[j].y) && binary_search(A,n,A[j].x,A[i].y)){
67				ans++;
68 		}
69	cout << ans << endl;
70	return 0;
71  }
  1. 1Fill in ( )
    A, a.X != b.x ? a.x < b.x : a.id < b.id
    B, a.x != b.x ? a.x < b.x : a.y < b.y
    C.equals(a,b) ? a.id < b.id : a.x < b.x

    D. equals(a,b) ? a.id < b,id : (a.x l= b.x ? a.x < b.x :a.y < b.y)

  2. 2Fill in ( )
    A, i=0 || cmp(A[i],A[i-1])
    B, t == 0 || equals(A[1],A[t - ])
    C, ii==0 || !cmp(A[i],A[i - 1])
    D,t==0 || !equals(A[i],A[t - 1])

  3. 3Fill in ( )
    A, b-(b-a)/2+1B, (a+b+1)>>1
    C, (a+b)>>1D,a+(b-a+1)/2

  4. 4Fill in ( )
    A, !cmp(A[mid],p)B, cmp(A[mid],P)
    C, cmp(p,A[mid])D,!cmp(P,A[mid])

  5. 5Fill in ( )
    A, A[i].x == A[j].x
    B, A[i].id < A[j].id
    C, A[i].x == A[j].X && A[i].id < A[j].id
    D,A[i].x < A[j].x && A[i].y < A[j].y

Guess you like

Origin blog.csdn.net/y6123236/article/details/131876198