2023-09-16 CSP-J First Round Preliminary Exam Questions Analysis

Score: 100

Exam time: 120 minutes

1. Multiple choice questions (15 questions in total, 2 points each, 30 points in total: each question has one and only one correct option) 1. In
C++, which of the following keywords is used to declare a variable whose value cannot be modified? ? (B) (2 points)
A. unsigned
B. const
C. static
D. mutable

2. The sum of the octal numbers 12345670₈ and 07654321₈ is (D). (2 points)
A. 22222221₈
B. 21111111₈
C. 22111111₈
D. 22222211₈

3. Read the following code and modify the value member of data to store 3.14. The correct way is (A). (2 minutes)

union Data{
    int num;
    float value;
    char symbol;
};
union Data data;

A. data.value = 3.14;
B. value.data = 3.14;
C. data->value = 3.14;
D. value->data = 3.14;

4. Suppose there is a linked list node defined as follows:

struct Node{
    int data;
    Node* next;
};


There is now a pointer pointing to the head of the linked list: Node* head. If you want to insert a new node in the table, the value of its member data is 42, and make the new node the first node of the linked list, which of the following operations is correct? ?(C)
A. Node* newNode = new Node; newNode->data = 42; newNode->next = head; head= newNode;
B. Node* newNode = new Node; head->data = 42; newNode- >next = head; head = newNode;
C. Node* newNode = new Node; newNode->data = 42; head->next = newNode;
D. Node* newNode = new Node; newNode->data = 42; newNode- >next = head;

5. The height of the root node is 1, and the height of a ternary tree with 2023 nodes is at least (A). (2 points)
A.6
B.7
C.8
D.9

6. Xiao Ming has seven free time periods in a certain day. He wants to select at least one free time period to practice singing, but he hopes that there are at least two free time periods between any two practice time periods. Let him rest, and Xiao Ming has a total of options to choose a time period. (B)(2 points)
A.31
B.18
C.21
D.33

7. The following statement about high-precision operations is incorrect (C). (2 points)
A. High-precision calculations are mainly used to process large integers or operations that require retaining multiple decimal places.
B. The steps for dividing a large integer by a small integer can be to align the dividend and divisor, one by one from left to right. Bit attempts to multiply the divisor by some number, subtract the new dividend, and accumulate the quotient.
C. The operation time of high-precision multiplication is only related to the number of digits in the longer of the two integers involved in the operation.
D. The key to high-precision addition is to add bit by bit and handle carry.

8. The corresponding middle expression of the postfix expression "6 2 3 + - 3 8 2 / + * 2 ^ 3 +" is (A). (2 points)
A. ((6 - (2 + 3))*(3 + 8 / 2)) ^ 2 
B.6 - 2 + 3 * 3 + 8 / 2 ^ 2 + 3
C.(6 - ( 2 + 3 )) * ((3 + 8 / 2) ^ 2) + 3
D.6 - ((2 + 3) * (3 + 8 / 2)) ^ 2 + 3

9. The sum of the numbers 101010₂ and 166₈ is (D). (2 points)
A.10110000₂
B.236₈
C.158₁₀
D.A0₁₆

10. Suppose there is a set of characters {a, b, c, d, e, f}, with corresponding frequencies of 5%, 9%, 12%, 13%, 16%, and 45% respectively. Which of the following options is a set of Huffman codes corresponding to the characters a, b, c, d, e, and f? (A) (2 points)
A. 1111, 1110, 101, 100, 110, 0
B. 1011, 1001, 1000, 011, 010, 100
C. 000, 001, 010, 011, 10, 11
D. 1010, 1011, 110, 111, 00, 01

11. Given a binary tree, the result of pre-order traversal is: ABCDEFG, and the result of in-order traversal is: DEBACFG. What is the correct traversal result of this tree? (A) (2 points)
A. EDBFGCA
B. EDBGCFA
C. DEBGFCA
D. DBEGFCA

12. Consider a directed acyclic graph, which contains 4 directed edges: (1, 2), (1, 3), (2, 4) and (3, 4). Which of the following options is this directed acyclic graph? An efficient topological sorting of ring graphs? (B) (2 points)


A. 4, 2, 3, 1
B. 1, 2, 3, 4
C. 1, 2, 4, 3
D. 2, 1, 3, 4

13. Which of the following options describes the smallest data storage capacity in a computer? (B) (2 points)
A. byte
B. bit
C. word
D. kilobyte

14. There are 10 boys and 12 girls in a class. If you want to select a group of 3 people, and the group must contain at least 1 girl, how many possible combinations are there? (A) (2 points)
A. 1420
B. 1770
C. 1540
D. 2200

15. Which of the following is not an operating system? (D) (2 points)
A. Linux
B. Windows
C. Android
D. HTML

2. Read the program (the program input does not exceed the range defined by the string formed by numbers: fill in √ for correct judgment questions and × for wrong answers; unless otherwise specified, 1.5 points for judgment questions and 3 points for multiple choice questions, a total of 40 points)

#include<iostream>
#include<cmath>
using namespace std;

double f(double a,double b,double c){
    double s=(a+b+c)/2;
    return sqrt(s*(s-a)*(s-b)*(s-c));
}

int main(){
    cout.flags(ios::fixed);
    cout.precision(4);
    
    int a,b,c;
    cin>>a>>b>>c;
    cout<<f(a,b,c)<<endl;
    return 0;
}

Assume that all the numbers entered are positive integers not exceeding 1000, complete the following true-false and multiple-choice questions:

·True or False

16. When the input is "2 2 2", the output is "1.7321" (correct) (2 points)
17. Change "(sb)*(sc)" in line 7 to "(sc)*(sb) )" will not affect the results of the program (True) (2 points)
18. The program always outputs four decimal places (True) (2 points)
·Multiple choice question
19. When the input is "3 4 5", the output is (A) (3 points)
A. "6.0000" 
B. "12.0000" 
C. "24.0000" 
D. "30.0000"

20. When the input is "5 12 13", the output is (B) (3 points)
A. "24.0000"
B. "30.0000"
C. "60.0000"
D. "120.0000"

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int f(string x,string y){
    int m=x.size();
    int n=y.size();
    vector<vector<int>>v(m+1,vector<int>(n+1,0));
   for(int i=1;i<=m;i++){
       for(int j=1;j<=n;j++){
            if(x[i-1]==y[j-1]){
                v[i][j]=v[i-1][j-1]+1;
            }else{
                v[i][j]=max(v[i-1][j],v[i][j-1]);
            }
        }
    }
    return v[m][n];
}

bool g(string x,string y){
    if(x.size() != y.size()){
        return false;
    }
    return f(x+x,y)==y.size();
}

int main(){
    string x,y;
    cin>>x>>y;
    cout<<g(x,y)<<endl;
    return 0;
}

·True or False Question
21. The return value of f function is less than or equal to min(n,m). (True) (1.5 points)
22. The return value of the f function is equal to the length of the longest common substring of the two input strings. (False) (1.5 points)
23. When two identical strings are input, the return value of the g function is always true (True) (1.5 points)
·Multiple choice question
24. Change "v[ in line 19 m][n]” is replaced with “v[n][m]”, then the program (B) (3 points)
A. has the same behavior
B. will only change the output
C. must exit abnormally
D. may be abnormal Exit
25. When the input is "csppsc spsccp", the output is: (B) (3 points)
A. "0"
B. "1"
C. "T"
D. "F"
26. When the input is "csppsc spsccp " ”, the output is (D). (3 points)
A. "T"
B. "F"
C. "0"
D. "1"

#include <iostream>
#include <cmath>
using namespace std;

int solve1(int n){
    return n*n;
}

int solve2(int n){
   int sum=0;
   for(int i=1;i<=sqrt(n);i++){
        if(n%i==0){
            if(n/i==i){
                sum+=i*i;
            }else{
                sum+=i*i+(n/i)*(n/i);
            }
        }
    }
    return sum;
}

int main(){
    int n;
    cin>>n;
    cout<<solve2(solve1(n))<<" "<<solve1((solve2(n)))<<endl;
    return 0;
}

Assume that the input n is an integer with an absolute value not exceeding 1000. Complete the following true-false and multiple-choice questions.

·True or False Question
27. If the input n is a positive integer, the function of solve2 function is to calculate the sum of the squares of all factors of n (pair) (1.5 points) 28. The function
of lines 13 to 14 is to avoid the square root factor i of n ( or n/i) enters line 16 and is calculated twice (right) (1.5 points)
29. If the input n is a prime number, the return value of solve2(n) is n2+1 (right) (1.5 points)
·Single Topic
30. If the input n is the square of prime number p, then the return value of solve2(n) is (B) (4 points)
A. p2+p+1 
B. n2+n+1 
C. n2+1 
D . p4+2p2+1
31. When the input is a positive integer, the difference between the first term minus the second term is certain (D) (3 points)
A. Greater than 0 B. Greater than or equal to 0 but not necessarily greater than 0 C. Less than 0 D. Less than or equal to 0 but not necessarily less than 0
32. When the input is "5", the output is (C) (3 points)
A. "651.625" 
B. "650.729" 
C. "651.676" 
D. "652.625 "

3. Improve the program (single-choice questions, 3 points for each question, 3 points in total)
(1) (Find the removed elements) Question: The original length is n+1 and the tolerance is 1 equal liter sequence. Enter the sequence into When an element is removed from the program's array, an open-order array of length n may no longer be contiguous unless the first or last element is removed. It is necessary to find the removed elements when the array is discontinuous. Try the completion program.

#include <iostream
#include <vector>

using namespace std;

int find missing(vector<int>& nums) {
    int left = 0, right = nums.size() - 1;
    while (left < right){
          int mid = left + (right  left) / 2;
         if (nums[mid] - mid+ ①) {
               ②;
           }else{
             ③
           }
      }
     return ④;
}

int main(){
    int n;
    cin >> n;
    vector<int> nums(n);
    for (int i= 0; i< n; i++) cin >> nums[i];
    int missing_number = find_missing(nums);
    if_(missing_number == ⑤) {
        cout << "Sequence is consecutive" << endl;
    }else{
           cout << "Missing number is " << ,missing numbeer << endl;
    }
    return 0;
}

 
33. ① should be filled in (B) (3 points)
A. 1 
B. nums[0] 
C. right 
D. left

34. ②处应填(A )(3分)
A. left=mid+1 
B. right=mid-1 
C. right=mid 
D. left=mid

35. ③ should be filled in (C) (3 points)
A.left=mid+1 
B.right=mid-1 
C.right=mid 
D.left=mid

36. ④ should be filled in (A) (3 points)
A.left+nums[0] 
B.right+nums[0] 
C.mid+nums[0] 
D.right+1

37. ⑤ should be filled in (D) (3 points)
A.nums[0]+n 
B.nums[0]+n-1 
C.nums[0]+n+1 
D.nums[n-1]

(2) (Edit distance) Given two strings, each operation can choose Delete, Insert, or Replace, one character. Find how to convert the first string into the second character. The minimum number of operations required for a string.

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int min(int x,int y,int z){
    return min(min(x,y),z);
}

int edit_dist_dp(string str1,string str2){
int m=str1.length();
int n=str2.length();
vector<vector<int>> dp(m+1,vector<int>(n+1));

for(int i=0;i<=m;i++){
    for(int j=0;j<=n;j++){
        if(i==0)
            dp[i][j]=(1);
        else if(j==0)
            dp[i][j]=(2);
        else if((3))
            dp[i][j]=(4);
        else
            dp[i][j]=1+min(dp[i][j-1],dp[i-1][j],(5)); 
    }
}
return dp[m][n];

int main(){
    string str1,str2;
    cin>>str1>>str2;
    cout<<"Mininum number of operation:"<<edit_dist_dp(str1,str2)<<endl;
    return 0; 
}

38. ① should be filled in with (A) (3 points)
A. j 
B. i 
C. m 
D. n

39. ② should be filled in (B) (3 points)
A. j 
B. i 
C. m 
D. n
 
40. ③ should be filled in (A) (3 points)
A. str1[i-1]==str2[ j-1] 
B. str1[i]==str2[j] 
C. str1[i-1]!=str2[j-1] 
D. str1[i]!=str2[j]

41. ④处应填(B )(3分)
A. dp[i-1][j-1]+1 
B. dp[i-1][j-1]
C. dp[i-1][j] 
D. dp[i][j-1]

42. ⑤处应填( C)(3分)
A. dp[i][j] + 1 
B. dp[i-1][j-1]+1
C. dp[i-1][j-1] 
D. dp[i][j]

Guess you like

Origin blog.csdn.net/m0_46227121/article/details/132919272