#C10001. CSP-J 2024真题

CSP-J 2024真题

CSP 2024 入门级第一轮

考试时间:2小时 | 满分:100分

一、单项选择题(共 15 题,每题 2 分,共计 30 分;每题有且仅有一个正确选项)

  1. 32位int类型的存储范围是?{{ select(1) }}
  • −2147483647-2147483647 ~ +2147483647+2147483647
  • −2147483647-2147483647 ~ +2147483648+2147483648
  • −2147483648-2147483648 ~ +2147483647+2147483647
  • −2147483648-2147483648 ~ +2147483648+2147483648

  1. 计算 ((148−10102)×D16−11012)((14_8 - 1010_2) \times D_{16} - 1101_2) 的结果,并选择答案的十进制值:{{ select(2) }}
  • 1313
  • 1414
  • 1515
  • 1616

  1. 某公司有 1010 名员工,分为 33 个部门:A 部门有 44 名员工,B部门有 33 名员工、C部门有 33 名员工。现需要从这 1010 名员工中选出 44 名组成一个工作组,且每个部门至少要有 11 人。问有多少种选择方式?{{ select(3) }}
  • 120120
  • 126126
  • 132132
  • 238238

  1. 以下哪个序列对应数组 00 至 88 的 44 位二进制格雷码(Gray code)?{{ select(4) }}
  • 0000,0001,0011,0010,0110,0111,0101,1000
  • 0000,0001,0011,0010,0110,0111,0100,0101
  • 0000,0001,0011,0010,0100,0101,0111,0110
  • 0000,0001,0011,0010,0110,0111,0101,0100
  1. 记 1KB=10241KB = 1024 字节(byte)(byte),1MB=1024KB1MB = 1024KB,那么 1MB1MB 是多少二进制位(bit)?{{ select(5) }}
  • 10000001000000
  • 10485761048576
  • 80000008000000
  • 83886088388608

  1. 以下哪个不是 C++C++ 中的基本数据类型?{{ select(6) }}
  • intint
  • floatfloat
  • structstruct
  • charchar

  1. 以下哪个不是 C++C++ 中的循环语句?{{ select(7) }}
  • forfor
  • whilewhile
  • do−whiledo-while
  • repeat−untilrepeat-until

  1. 在 C/C++C/C++ 中,(char)('a' + 13) 与下面的哪一个值相等?{{ select(8) }}
  • 'm'
  • 'n'
  • 'z'
  • 'I'

  1. 假设有序表中有 10001000 个元素,则用二分法查找元素x最多需要比较几次?{{ select(9) }}
  • 2525
  • 1010
  • 77
  • 11

  1. 下面哪一个不是操作系统名字?{{ select(10) }}
  • Notepad
  • Linux
  • Windows
  • macOS

  1. 在无向图中,所有顶点的度数之和等于?{{ select(11) }}
  • 图的边数
  • 图的边数的两倍
  • 图的顶点数
  • 图的顶点数的两倍

  1. 已知二叉树的前序遍历为 [A,B,D,E,C,F,G][A,B,D,E,C,F,G],中序遍历为 [D,B,E,A,F,C,G][D,B,E,A,F,C,G],求二叉树的后序遍历的结果是?{{ select(12) }}
  • [D,E,B,F,G,C,A][D,E,B,F,G,C,A]
  • [D,E,B,F,G,A,C][D,E,B,F,G,A,C]
  • [D,B,E,F,G,C,A][D,B,E,F,G,C,A]
  • [D,B,E,F,G,A,C][D,B,E,F,G,A,C]

  1. 给定一个空栈,支持入栈和出栈操作。若入栈操作的元素依次是1,2,3,4,5,61,2,3,4,5,6,其中 11 最先入栈,66 最后入栈,下面哪种出栈顺序是不可能的?{{ select(13) }}
  • 6,5,4,3,2,16,5,4,3,2,1
  • 1,6,5,4,3,21,6,5,4,3,2
  • 2,4,6,5,3,12,4,6,5,3,1
  • 1,3,5,2,4,61,3,5,2,4,6

  1. 有 55 个男生和 33 个女生站成一排,规定 33 个女生必须相邻,问有多少种不同的排列方式?{{ select(14) }}
  • 4320 种
  • 5040 种
  • 3600 种
  • 2880 种

  1. 编译器的主要作用是什么?{{ select(15) }}
  • 直接执行源代码
  • 将源代码转换为机器代码
  • 进行代码调试
  • 管理程序运行时的内存

二、阅读程序题(程序输入不超过数组或字符串定义的范围;判断题正确填√,错误填×;除特殊说明外,判断题每题1.5分,选择题每题3分,共计40分)

(阅读程序一)

阅读以下程序,回答第16~20题。

#include <iostream>
using namespace std;

bool isPrime(int n) {
    if (n <= 1) {
        return false;
    }
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int countPrimes(int n) {
    int count = 0;
    for (int i = 2; i <= n; i++) {
        if (isPrime(i)) {
            count++;
        }
    }
    return count;
}

int sumPrimes(int n) {
    int sum = 0;
    for (int i = 2; i <= n; i++) {
        if (isPrime(i)) {
            sum += i;
        }
    }
    return sum;
}

int main() {
    int x;
    cin >> x;
    cout << countPrimes(x) << " " << sumPrimes(x) << endl;
    return 0;
}
  1. 当输入为"10"时,程序的第一个输出为"4",第二个输出为"17"。{{ select(16) }}
  • 正确
  • 错误

  1. 若将 isPrime(i)isPrime(i) 函数中的条件改为i <=n/2<= n/2,输入"20"时,countPrimes(20)countPrimes(20) 的输出将变为"6"。{{ select(17) }}
  • 正确
  • 错误

  1. sumPrimessumPrimes 函数计算的是从 22 到 nn 之间的所有素数之和。{{ select(18) }}
  • 正确
  • 错误

单选题

  1. 当输入为"50"时,sumPrimes(50)sumPrimes(50) 的输出为( )。{{ select(19) }}
  • 10601060
  • 328328
  • 381381
  • 275275

  1. 如果将for(int i = 2; i * i <= n; i++)改为for(int i = 2; i <= n; i++),输入"10"时,程序的输出( )。{{ select(20) }}
  • 将不能正确计算10以内素数个数及其和
  • 仍然输出"4"和"17"
  • 输出"3"和"10"
  • 输出结果不变,但运行时间更短

(阅读程序二)

阅读以下程序,回答第21~26题。

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

int compute(vector<int>& cost) {
    int n = cost.size();
    vector<int> dp(n + 1, 0);
    dp[1] = cost[0];
    for (int i = 2; i <= n; i++) {
        dp[i] = min(dp[i - 1], dp[i - 2]) + cost[i - 1];
    }
    return min(dp[n], dp[n - 1]);
}

int main() {
    int n;
    cin >> n;
    vector<int> cost(n);
    for (int i = 0; i < n; i++) {
        cin >> cost[i];
    }
    cout << compute(cost) << endl;
    return 0;
}

判断题

  1. 当输入的 costcost 数组为{10,15,20}\{10, 15, 20\} 时,程序的输出为15。{{ select(21) }}
  • 正确
  • 错误

  1. 如果将 dp[i−1]dp[i-1] 改为 dp[i−3]dp[i-3],程序可能会产生编译错误。{{ select(22) }}
  • 正确
  • 错误

  1. (2分)程序总是输出 costcost 数组中最小的元素。{{ select(23) }}
  • 正确
  • 错误

单选题

  1. 当输入的 costcost 数组为{1,100,1,1,1,100,1,1,100,1}\{1, 100, 1, 1, 1, 100, 1, 1, 100, 1\} 时,程序的输出为( )。{{ select(24) }}
  • 66
  • 77
  • 88
  • 99

  1. (4分)如果输入的 costcost 数组为 {10,15,30,5,5,10,20}\{10, 15, 30, 5, 5, 10, 20\},程序的输出为( )。{{ select(25) }}
  • 2525
  • 3030
  • 3535
  • 4040

  1. 若将代码中的min(dp[i-1], dp[i-2]) + cost[i-1]修改为dp[i-1] + cost[i-2],输入 costcost 数组为{5,10,15}\{5, 10, 15\}时,程序的输出为( )。{{ select(26) }}
  • 1010
  • 1515
  • 2020
  • 2525

(阅读程序三)

阅读以下程序,回答第27~32题。

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

int customFunction(int a, int b) {
    if (b == 0) {
        return a;
    }
    return a + customFunction(a , b - 1);
}

int main() {
    int x, y;
    cin >> x >> y;
    int result = customFunction(x, y);
    cout << pow(result, 2) << endl;
    return 0;
}

判断题

  1. 当输入为"2 3"时,customFunction(2,3)customFunction(2, 3) 的返回值为"64"。{{ select(27) }}
  • 正确
  • 错误

  1. (本题为错题,请同时选择【正确】和【错误】获得对应分数)当b为负数时,customFunction(a,b)customFunction(a, b) 会陷入无限递归。{{ multiselect(28) }}
  • 正确
  • 错误

  1. (本题为错题,请同时选择【正确】和【错误】获得对应分数)当b的值越大,程序的运行时间越长。{{ multiselect(29) }}
  • 正确
  • 错误

单选题

  1. 当输入为"5 4"时,customFunction(5,4)customFunction(5, 4) 的返回值为( )。{{ select(30) }}
  • 55
  • 2525
  • 250250
  • 625625

  1. 如果输入 x=3x = 3 和 y=3y = 3,则程序的最终输出为( )。{{ select(31) }}
  • 2727
  • 8181
  • 144144
  • 256256

  1. 若将 customFunctioncustomFunction 函数改为returna+customFunction(a−1,b−1);return a + customFunction(a - 1, b - 1);并输入"3 3",则程序的最终输出为( )。{{ select(32) }}
  • 99
  • 1616
  • 2525
  • 3636

三、完善程序题(单选题,每小题3分,共计30分)

(完善程序一)

以下程序用于判断一个给定的正整数 n 是否为完全平方数,即是否存在一个正整数 x 使得 x 的平方等于 n。试补全程序。

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

bool isSquare(int num){
    int i = ___(1)___;
    int bound = ___(2)___;
    for(; i <= bound; ++i){
        if(___(3)___){
            return ___(4)___;
        }
    }
    return ___(5)___;
}

int main(){
    int n;
    cin >> n;
    if(isSquare(n)){
        cout << n << " is a Square number" << endl;
    }else{
        cout << n << " is not a Square number" << endl;
    }
    return 0;
}
  1. ①处应填( )。{{ select(33) }}
  • 11
  • 22
  • 33
  • 44

  1. ②处应填( )。{{ select(34) }}
  • (int)floor(sqrt(num))−1(int)floor(sqrt(num))-1
  • (int)floor(sqrt(num))(int)floor(sqrt(num))
  • floor(sqrt(num/2))−1floor(sqrt(num / 2)) - 1
  • floor(sqrt(num/2))floor(sqrt(num / 2))

  1. ③处应填( )。{{ select(35) }}
  • num=2∗inum = 2 * i
  • num==2∗inum == 2 * i
  • num=i∗inum = i * i
  • num==i∗inum == i * i
  1. ④处应填( )(本题有多个可能选项)。{{ multiselect(36) }}
  • num=2∗inum = 2 * i
  • num==2∗inum == 2 * i
  • truetrue
  • falsefalse

  1. ⑤处应填( )。{{ select(37) }}
  • num=i∗inum = i * i
  • num!=2∗inum != 2 * i
  • truetrue
  • falsefalse

(完善程序二)

(汉诺塔问题)给定三根柱子,分别标记为A、B和C。初始状态下,柱子A上有若干个圆盘,这些圆盘从上到下按从小到大的顺序排列。任务是将这些圆盘全部移到柱子C上,且必须保持原有顺序不变。在移动过程中,需要遵守以下规则:

  1. 只能从一根柱子的顶部取出圆盘,并将其放入另一根柱子的顶部。
  2. 每次只能移动一个圆盘。
  3. 小圆盘必须始终在大圆盘之上。

试补全程序。

#include <bits/stdc++.h>
using namespace std;

void move(char src, char tgt) {
    cout << "从柱子" << src << "挪到柱子" << tgt << endl;
}

void dfs(int i, char src, char tmp, char tgt) {
    if (i == ___(1)___) {
        move(___(2)___);
        return;
    }
    dfs(i - 1, ___(3)___);
    move(src, tgt);
    dfs(___(5)___, ___(4)___);
}

int main() {
    int n;
    cin >> n;
    dfs(n, 'A', 'B', 'C');
    return 0;
}
  1. ①处应填( )。{{ select(38) }}
  • 00
  • 11
  • 22
  • 33

  1. ②处应填( )。{{ select(39) }}
  • src,tmpsrc, tmp
  • src,tgtsrc, tgt
  • tmp,tgttmp, tgt
  • tgt,tmptgt, tmp

  1. ③处应填( )。{{ select(40) }}
  • src,tmp,tgtsrc, tmp, tgt
  • src,tgt,tmpsrc, tgt, tmp
  • tgt,tmp,srctgt, tmp, src
  • tgt,src,tmptgt, src, tmp

  1. ④处应填( )。{{ select(41) }}
  • src,tmp,tgtsrc, tmp, tgt
  • tmp,src,tgttmp, src, tgt
  • src,tgt,tmpsrc, tgt, tmp
  • tgt,src,tmptgt, src, tmp

  1. ⑤处应填( )。{{ select(42) }}
  • 00
  • 11
  • i−1i - 1
  • ii