#F. CSP 2024 入门级第一轮

    Type: Objective

CSP 2024 入门级第一轮

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

一、单项选择题

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

【第 1 题】

32 位 int 类型的存储范围是( )。 {{ select(1) }}

  • -2147483647 ~ +2147483647
  • -2147483647 ~ +2147483648
  • -2147483648 ~ +2147483647
  • -2147483648 ~ +2147483648

【第 2 题】

计算 (14810102)D1611012(14_8−1010_2)∗D_{16}−1101_2 的结果,并选择答案的十进制值: {{ select(2) }}

  • 13
  • 14
  • 15
  • 16

【第 3 题】

某公司有 10 名员工,分为 3 个部门:A 部门有 4 名员工,B 部门有 3 名员工、C 部门有 3 名员工。现需要从这 10 名员工中选出 4 名组成一个工作组,且每个部门至少要有1人。问有多少种选择方式?( )。

{{ select(3) }}

  • 120
  • 126
  • 132
  • 328

【第 4 题】

以下哪个序列对应数组0至8的4位二进制格雷码(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

【第 5 题】

记1Kb位1024字节(byte),1MB位1024KB,那么1MB是多少二进制位(bit)?( ) {{ select(5) }}

  • 1000000
  • 1048576
  • 8000000
  • 8388608

【第 6 题】

以下哪个不是C++中的基本数据类型?( ) {{ select(6) }}

  • int
  • float
  • struct
  • char

【第 7 题】

以下哪个不是C++中的循环语句?( ) {{ select(7) }}

  • for
  • while
  • do-while
  • repeat-untill

【第 8 题】

在C/C++中,(char)('a'+13)与下面的哪一个值相等( )。 {{ select(8) }}

  • 'm'
  • 'n'
  • 'z'
  • '3'

【第 9 题】

假设有序表中有 1000个 元素,则用二分法查找元素x最多需要比较( )次。 {{ select(9) }}

  • 25
  • 10
  • 7
  • 1

【第 10 题】

下面哪一个不是操作系统名字( ) {{ select(10) }}

  • Notepad
  • Linux
  • Windows
  • macOS

【第 11 题】

在无向图中,所有顶点的度数之和等于( )。 {{ select(11) }}

  • 图的边数
  • 图的边数的两倍
  • 图的定点数
  • 图的定点数的两倍

【第 12 题】 已知二叉树的前序遍历为 [A,B,D,E,C,F,G],中序遍历为 [D,B,E,A,F,C,G],求二叉树的后序遍历的结果是( )。 {{ select(12) }}

  • [D,E,B,F,G,C,A]
  • [D,E,B,F,G,A,C]
  • [D,B,E,F,G,C,A]
  • [D,B,E,F,G,A,C]

【第 13 题】 给定一个空栈,支持入栈和出栈操作。若入栈操作的元素依次是 1 2 3 4 5 6,其中 1 最先入栈,6 最后入栈,下面哪种出栈顺序是不可能的( )。 {{ select(13) }}

  • 6 5 4 3 2 1
  • 1 6 5 4 3 2
  • 2 4 6 5 3 1
  • 1 3 5 2 4 6

【第 14 题】

有5个男生和3个女生站成一排,规定3个女生必须相邻,问有多少种不同的排列方式?( ) {{ select(14) }}

  • 4320种
  • 5040种
  • 3600种
  • 2880种

【第 15 题】

编译器的主要作用是什么( )。 {{ select(15) }}

  • 直接执行源代码
  • 将源代码转换为机器代码
  • 进行代码调试
  • 管理程序运行时的内存

二、阅读程序

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

阅读程序(一)

01 #include <iostream>
02 using namespace std;
03
04 bool isPrime(int n) {
05    if (n <= 1) {
06        return false;
07    }
08    for (int i = 2; i * i <= n; i++) {
09       if (n % i == 0) {
10          return false;
11      }
12    }
13    return true;
14 }
15
16 int countPrimes(int n) {
17    int count = 0;
18    for (int i = 2; i <= n; i++) {
19        if (isPrime(i)) {
20            count++;
21        }
22     }
23     return count;
24 }
25
26 int sumPrimes(int n) {
27    int sum = 0;
28    for (int i = 2; i <= n; i++) {
29          if (isPrime(i)) {
30              sum += i;
31          }
32     }
33     return sum;
34 }
35
35 int main() {
37    int x;
38    cin >> x;
39    cout << countPrimes(x) << " " << sumPrimes(x) << endl;
40    return 0;
41 }

假设输入的所有数都为不超过 1000 的正整数,完成下面的判断题和单选题:

判断题

  1. 当输入为“10”时,程序的第一个输出为“4”,第二个输出为“17”。 {{ select(16) }}
  • 正确
  • 错误
  1. 若将 isPrime(i) 函数种的条件改为 i<=n/2,输入“20”时,countPrimes(20) 的 输出将变为“6”。 {{ select(17) }}
  • 正确
  • 错误
  1. sumPrimes 函数计算的是从 2 到 n 之间的所有素数之和。 {{ select(18) }}
  • 正确
  • 错误

单选题

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

阅读程序(二)

01 #include <iostream>
02 #include <vector>
03 using namespace std;
04
05 int compute(vector<int> &cost) {
06    int n = cost.size();
07    vector<int> dp(n + 1, 0);
08    dp[1] = cost[0];
09    for (int i = 2; i <= n; i++) {
10        dp[i] = min(dp[i - 1], dp[i - 2]) + cost[i - 1];
11    }
12    return min(dp[n], dp[n - 1]);
13 }
14
15 int main() {
16    int n;
17    cin >> n;
18    vector<int> cost(n);
19    for (int i = 0; i < n; i++) {
20        cin >> cost[i];
21    }
22    cout << compute(cost) << endl;
23    return 0;
24 }

判断题

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

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

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

单选题

  1. 当输入的 cost 数组为{1,100,1,1,1,100,1,1,100,1}时,程序的输出为( )。 {{ select(24) }}
  • 6
  • 7
  • 8
  • 9
  1. (4分)如果输入的 cost 数组为{10,15,30,5,5,10,20},程序的输出为( )。 {{ select(25) }}
  • 25
  • 30
  • 35
  • 40
  1. 若将代码中的 min(dp[i-1],dp[i-2])+cost[i-1] 修改为 dp[i-1]+cost[i-2],输入 cost 数组为 {5,10,15} 时,程序的输出为( )。 {{ select(26) }}
  • 10
  • 15
  • 20
  • 25

阅读程序(三)

01 #include <iostream>
02 #include <cmath>
03 using namespace std;
04
05 int customFunction(int a, int b) {
06    if (b == 0) {
07        return a;
08    }
09    return a + customFunction(a, b - 1);
10 }
11
12 int main() {
13    int x, y;
14    cin >> x >> y;
15    int result = customFunction(x, y);
16    cout << pow(result, 2) << endl;
17    return 0;
18 }

判断题

  1. 当输入为“2 3”时,customFunction(2,3)的返回值为“64”。

    {{ select(27) }}

  • 正确
  • 错误
  1. 当 b 为负数时,customFunction(a,b)会陷入无限递归。 {{ select(28) }}
  • 正确
  • 错误
  1. 当 b 的值越大,程序的运行时间越长。 {{ select(29) }}
  • 正确
  • 错误

单选题

  1. 当输入为“5 4”时,customFunction(5,4) 的返回值为( )。 {{ select(30) }}
  • 5
  • 25
  • 250
  • 625
  1. 如果输入x = 3 和 y = 3,则程序的最终输出为( )。 {{ select(31) }}
  • 27
  • 81
  • 144
  • 256
  1. (4分)若将customFunction函数改为“return a + customFunction(a-1,b-1);并输入“3 3”,则程序的最终输出为( )。 {{ select(32) }}
  • 9
  • 16
  • 25
  • 36

三、程序填空

(单选题,每小题 3 分,共计 30 分)

程序填空(一)

  1. (判断平方数) 问题:给定一个正整数 n,判断这个数是不是完全平方数,即存在一个正整数 x 使得 x 的平方等于 n。 试补全程序
#include <iostream>
#include <vector>
using namespace std;
bool isSquare(int num)
{
    int i = ①;
    int bound = ②;
    for (; i <= bound; ++i)
    {
        if (③)
        {
            return ④;
        }
    }
    return ⑤;
}
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) }}
  • 1
  • 2
  • 3
  • 4
  1. ② 处应填( )。 {{ select(34) }}
  • (int)floor(sqrt(num)-1)
  • (int)floor(sqrt(num))
  • floor(sqrt(num/2))-1
  • floor(sqrt(num/2))
  1. ③ 处应填( )。 {{ select(35) }}
  • num=2*i
  • num== 2*i
  • num=i*i
  • num==i*i
  1. ④ 处应填( )。 {{ select(36) }}
  • num= 2*i
  • num==2*i
  • true
  • false
  1. ⑤ 处应填( )。 {{ select(37) }}
  • num= i*i
  • num!=2*I
  • true
  • false

完善程序(二)

2.(汉诺塔问题)给定三根柱子,分别标记为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 == ①)
    {
        move(②);
        return;
    }
    dfs(i - 1, ③);
    move(src, tgt);
    dfs(⑤, ④);
}
int main()
{
    int n;
    cin >> n;
    dfs(n, 'A', 'B', 'C');
    return 0;
}
  1. ① 处应填( )。 {{ select(38) }}
  • 0
  • 1
  • 2
  • 3
  1. ② 处应填( )。 {{ select(39) }}
  • src,tmp
  • src,tgt
  • tmp,tgt
  • tgt,tmp
  1. ③ 处应填( )。 {{ select(40) }}
  • src,tmp,tgt
  • src, tgt, tmp
  • tgt, tmp, src
  • tgt, src, tmp
  1. ④ 处应填( )。 {{ select(41) }}
  • src, tmp, tgt
  • tmp,src, tgt
  • src, tgt,tmp
  • tgt,src,tmp
  1. ⑤ 处应填( )。 {{ select(42) }}
  • 0
  • 1
  • i-1
  • i

CSP-J 真题+模拟题

Not Attended
Status
Done
Rule
OI
Problem
10
Start at
2024-9-22 6:00
End at
2024-9-30 14:00
Duration
200 hour(s)
Host
Partic.
107