#CSPJSH10. 珅泽教育CSP-J第一轮模拟考第十套

珅泽教育CSP-J第一轮模拟考第十套

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

  1. 3232 位无符号位 int 类型的存储范围是( )。

{{ select(1) }}

  • 042949672950 \sim 4294967295
  • 21474836482147483647-2147483648 \sim 2147483647
  • 042949672960 \sim 4294967296
  • 0655350 \sim 65535
  1. 以下判断一个正整数 n 是否是偶数的代码中,错误的是( )。

{{ select(2) }}

  • if (n % 2 == 0)
  • if (!(n % 2))
  • if (n & 1)
  • if (n % 2 != 1)
  1. C++ 中,5 ^ -55 & -5 的值分别为( )。

{{ select(3) }}

  • 2,1-2, 1
  • 2,12, -1
  • 2,1-2, -1
  • 2,12, 1
  1. 一棵哈夫曼树,拥有 1313 个叶结点。则该哈夫曼树的结点总数为( )。

{{ select(4) }}

  • 2525
  • 2626
  • 2727
  • 无法确定
  1. 下列关于树的描述中正确的是( )。

{{ select(5) }}

  • nn 个结点的树,边数只能是 n1n-1 条。
  • 在哈夫曼树中,叶子结点的比非叶子结点多 1122 个。
  • 完全二叉树是二叉排序树。
  • 在二叉树的后序遍历序列中,若结点 uu 在结点 vv 之前,则 uu 一定是 vv 的祖先
  1. 下面代码构成的是( )类型的数据结构。
struct Node
{
    int value;
    Node* link;
};
Node* add(Node* node, int value)
{
    Node* new_node = new Node;
    new_node->link = node;
    new_node->value = value;
    return new_node;
}
Node* del(Node* node)
{
    Node* new_node = node->link;
    delete node;
    return new_node;
}
int main()
{
    Node* head = add(nullptr, 1);
    head = add(head, 2);
    head = del(head);
}

{{ select(6) }}

  • 双向链表
  • 循环链表
  • 队列
  1. 以下代码调用 F(n) 的时间复杂度为( )。
int F(int n)
{
    if (n <= 2)
        return 1;
    else
        return F(n-1) + F(n-2);
}

{{ select(7) }}

  • Θ(1)\Theta(1)
  • Θ(n)\Theta(n)
  • Θ(n2)\Theta(n^2)
  • Θ(2n)\Theta(2^n)
  1. 在简单图中,有 nn 个顶点的强连通图最少有( )条边,最多有( )条边。

{{ select(8) }}

  • n1,nn-1, n
  • n1,n(n1)n-1, n(n-1)
  • n,n(n1)n, n(n-1)
  • n,n(n1)/2n, n(n-1)/2
  1. 以下关于强连通图的说法中,正确的是( )。

{{ select(9) }}

  • 图中一定有环
  • 每个顶点的度数都大于 00
  • 对于大于 11 个点的强连通图,任意两个顶点之间都有路径相连
  • 每个顶点至少都连有一条边
  1. 用线性探测法把 kk 个关键字相同但内容不同的数据存入哈希表中,至少要进行( )次探测。

{{ select(10) }}

  • k+1k+1
  • k1k-1
  • (k+1)k/2(k+1)\cdot k/2
  • (k1)k/2(k-1)\cdot k/2
  1. a,b,c,d,e,f 六个字母的全排列中不允许出现 acedf 子串的排列数( )。

{{ select(11) }}

  • 177177
  • 377377
  • 477477
  • 582582
  1. 一堆卡片共 20252025 张,设定一个数量,不断从牌堆中取该数量的牌,记 AA 表示该数量为素数的方案数,记 BB 为该数量为奇数的方案数。则 A+B=A+B=( )。

{{ select(12) }}

  • 1616
  • 1717
  • 1818
  • 1919
  1. 若存在正整数 k(1kn1)k(1 \le k \le n-1) 使得 C(n,k1)C(n,k-1)C(n,k)C(n,k)C(n,k+1)C(n,k+1) 构成等差数列(其中 C(n,k)C(n,k) 为组合数,且 C(n,k)=n!k!(nk)!C(n,k)=\frac{n!}{k!(n-k)!}),则不超过 20252025 的质数个数为( )。

{{ select(13) }}

  • 1414
  • 1515
  • 2222
  • 4343
  1. 已知一棵二叉树有 20252025 个结点,则其中至多有( )个结点有 22 个子结点。

{{ select(14) }}

  • 10101010
  • 10111011
  • 10121012
  • 10131013
  1. 从乘法算式 $1 \times 2 \times 3 \times 4 \times \cdots \times 24 \times 25$ 中,最少要删掉( )个数才能使剩下的数的乘积是完全平方数。共有( )种不同的删除方法。

{{ select(15) }}

  • 3,13, 1
  • 3,23, 2
  • 5,25, 2
  • 5,15, 1

二、阅读程序(判断题正确填T,错误填F;判断题1分,选择题3分,共计40分)

第1题

int solve(int n, int a[], int b[])
{
    std::sort(a, a + n);
    std::sort(b, b + n);
    int ans = std::max(a[0] - b[0], b[0] - a[0]);
    int i = 0;
    int j = 0;
    while (i < n && j < n)
    {
        if (a[i] < b[j])
        {
            int diff = b[j] - a[i];
            if (ans > diff)
                ans = diff;
            i++;
        }
        else
        {
            int diff = a[i] - b[j];
            if (ans > diff)
                ans = diff;
            j++;
        }
    }
    return ans;
}

判断题

  1. a[0] == b[0] 时,程序返回 0。( )。

{{ select(16) }}

  • 正确
  • 错误
  1. 若程序在运行时,跳过了数组 ab 的排序步骤,程序会进入死循环。( )。

{{ select(17) }}

  • 正确
  • 错误
  1. 当输入数据出现负数时,程序可能返回负数( )。

{{ select(18) }}

  • 正确
  • 错误

选择题

  1. n=3a=[5, 1, 12]b=[7, 9, 4],程序的输出结果是( )。

{{ select(19) }}

  • 1
  • 2
  • 3
  • 4
  1. 程序返回的是( )。

{{ select(20) }}

  • 数组 a 中的元素与数组 b 中的元素的最大差值
  • 数组 a 中的元素与数组 b 中的元素的最小差值
  • 数组 a 的最大值与数组 b 最小值的差
  • 数组 b 的最大值与数组 a 最小值的差
  1. 该程序的时间复杂度为( )。

{{ select(21) }}

  • Θ(n2)\Theta(n^2)
  • Θ(nlogn)\Theta(n\log n)
  • Θ(n)\Theta(n)
  • Θ(log2n)\Theta(\log^2 n)

第2题

int solve(int n, int a[])
{
    int ret = 0;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < i; ++j)
        {
            int sum = 0;
            for (int k = j; k <= i; ++k)
            {
                sum += a[k];
            }
            ret += sum;
        }
    }
    return ret;
}

判断题

  1. 若在进入 solve 函数执行其他操作之前,先对 a[] 排序,返回值不变( )。

{{ select(22) }}

  • 正确
  • 错误
  1. n=1n=1 时,函数返回值为 a[0]( )。

{{ select(23) }}

  • 正确
  • 错误
  1. 若数组 a[] 中所有元素均为 00,则当 nn11100100 之间的整数时,函数一定返回 00( )。

{{ select(24) }}

  • 正确
  • 错误

选择题

  1. n = 10a = {1, 1, ..., 1},程序的返回值是( )。

{{ select(25) }}

  • 1010
  • 100100
  • 165165
  • 210210
  1. n = 5,且 a = {3, 1, 4, 1, 5},则程序返回( )。

{{ select(26) }}

  • 1414
  • 7575
  • 7878
  • 8080
  1. 该程序的时间复杂度为( )。

{{ select(27) }}

  • Θ(n)\Theta(n)
  • Θ(n2)\Theta(n^2)
  • Θ(n2logn)\Theta(n^2 \cdot \log n)
  • Θ(n3)\Theta(n^3)
  1. 改进 solve 函数,最佳改进算法的时间复杂度为( )。

{{ select(28) }}

  • Θ(n)\Theta(n)
  • Θ(n2)\Theta(n^2)
  • Θ(n2logn)\Theta(n^2 \cdot \log n)
  • Θ(n3)\Theta(n^3)

第三题

using std::string;

string post(const string& pre, const string& in)
{
    if (pre == "") return "";
    char root = pre[0];

    int i = 0;
    while (root != in[i]) ++i;

    string left_in = in.substr(0, i);
    string right_in = in.substr(i+1);

    string left_pre = pre.substr(1, i);
    string right_pre = pre.substr(i+1);

    string left_post = post(left_pre, left_in);
    string right_post = post(right_pre, right_in);

    return left_post + right_post + root;
}

判断题

  1. 去掉参数 preconst 修饰符,程序会发生编译错误( )。

{{ select(29) }}

  • 正确
  • 错误
  1. 去掉参数 pre&,程序会发生编译错误( )。

{{ select(30) }}

  • 正确
  • 错误
  1. 当参数 pre 中出现参数 in 所没有的字符时,程序会发生运行时错误( )。

{{ select(31) }}

  • 正确
  • 错误
  1. 当程序正常运行时,post 函数返回的字符串与参数 pre 等长( )。

{{ select(32) }}

  • 正确
  • 错误

选择题

  1. 当输入 pre = "ABDEC"in = "DBEAC",函数返回( )。

{{ select(33) }}

  • ABDEC
  • DBECA
  • DEBCA
  • DBEAC
  1. 当输入 pre = "*+12-34"in = "1+2*3-4",函数返回( )。

{{ select(34) }}

  • 1234+-*
  • 43-21+*
  • 4-3*2+1
  • 12+34-*
  1. 当输入 pre = "12345"in = "54321" 时,函数返回( )。

{{ select(35) }}

  • 53241
  • 54321
  • 12345
  • 45321

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

第1题

给定 nn 根火柴的长度 a1,a2,,ana_1,a_2,\cdots,a_n,请用这些火柴围成一个面积最大的三角形。注意所有的火柴都必须用上,不得丢弃。输出最大三角形的面积。假设最大面积为 ss,则输出 16s216s^21ai401 \le a_i \le 40,数据保证至少有一种方案可以围成三角形。

#include<iostream>
using i64 = long long;
int n;
int a[40];
bool mem[40][40*40][40*40];
i64 value[40][40*40][40*40];

i64 solve(int i, int x, int y, int z)
{
    if (i < n)
    {
        if (mem ____(1)____ > 0)
            return value ____(2)____;
        i64 s1 = solve(i+1, x + a[i], y, z);
        i64 s2 = solve(i+1, x, y + a[i], z);
        i64 s3 = solve(i+1, x, y, z + a[i]);
        mem[i][x][y] = true;
        return value[i][x][y] = ____(3)____;
    }
    else
    {
        if ( ____(4)____ ) return 0;
        i64 p = ____(5)____ ;
        return ____(6)____ ;
    }
}

int solve()
{
    std::cin >> n;
    for (int i = 0; i < n; ++i)
    {
        std::cin >> a[i];
    }
    std::cout << solve(0, 0, 0, 0);
}
  1. (1)(2) 处应填( )。

{{ select(36) }}

  • [i][x][y],[i][x][y]
  • [i][x][y],[x][y][z]
  • [x][y][z],[i][x][y]
  • [x][y][z],[x][y][z]
  1. (3) 处应填( )。

{{ select(37) }}

  • s1 + s2 + s3
  • *std::max_element({s1, s2, s3}.begin(), {s1, s2, s3}.end())
  • std::max(std::max(s1, s2), std::max(s3, z))
  • std::max(std::max(s1, s2), s3)
  1. (4) 处应填( )。

{{ select(38) }}

  • x + y <= z && x + z <= y && y + z <= x
  • x + y <= z || x + z <= y || y + z <= x
  • x + y > z || x + z > y || y + z > x
  • x + y >= z && x + z >= y && y + z >= x
  1. (5) 处应填( )。

{{ select(39) }}

  • x * y * z
  • x + y + z
  • (x * y) / 2
  • (x + y + z) / 2
  1. (6) 处应填( )。

{{ select(40) }}

  • p * (p - 2 * x) * (p - 2 * y)
  • (p / 2) * (p / 2 - x) * (p / 2 - y) * (p / 2 - z)
  • p * (p - 2 * x) * (p - 2 * y) * (p - 2 * z)
  • p + (p - 2 * x) + (p - 2 * y) + (p - 2 * z)

第2题

给定一个 N×MN \times M 的迷宫网格(含不可通行的 #、可通行的 .、双向必传送且耗时 00 的滑梯对(大写字母)、出口 = 和起点 @),从起点出发,移动相邻草地耗时 11,传送耗时 00。计算从起点到达出口所需的最短时间。

#include<iostream>
char a[1000][1000];
int d[1000][1000];
int n, m;
int qx[1000*1000];
int qy[1000*1000];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sumx[26];
int sumy[26];
void bfs(int x, int y) {
    qx[0] = x;
    qy[0] = y;
    d[x][y] = 1;
    int head = 0;
    int tail = 1;
    while (head < tail) {
        int x = qx[____(1)____];
        int y = qy[____(2)____];
        ____(3)____++;
        for (int k = 0; k < 4; ++k) {
            int nx = x + dx[k];
            int ny = y + dy[k];
            if (____(4)____) {
                if (____(5)____) continue;

                if ('A' <= a[nx][ny] and a[nx][ny] <= 'Z') {
                    char c = a[nx][ny];
                    nx = ____(6)____ ;
                    ny = ____(7)____ ;
                }

                if ( ____(8)____ ) {
                    d[nx][ny] = ____(9)____ ;
                    qx[tail] = nx;
                    qy[tail] = ny;
                    tail++;
                }
            }
        }
    }
}

int main()
{
    std::cin >> n >> m;
    int sx, sy, tx, ty;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j) {
            std::cin >> a[i][j];
            if (a[i][j] == '@') {sx = i; sy = j;}
            if (a[i][j] == '=') {tx = i; ty = j;}
            if ('A' <= a[i][j] and a[i][j] <= 'Z') {
                sumx[a[i][j] - 'A'] += i;
                sumy[a[i][j] - 'A'] += j;
            }
        }
    bfs(sx, sy);
    std::cout << ____(10)____ << "\n";
}
  1. (1)(2)(3) 处应填( )。

{{ select(41) }}

  • head,head,head
  • head,head,tail
  • tail,tail,head
  • tail,tail,tail
  1. (4)(5) 处应填( )。

{{ select(42) }}

  • 0 <= nx or nx < n or 0 <= ny or ny < m, a[nx][ny] == '#'
  • 0 <= nx and nx < n and 0 <= ny and ny < m, a[nx][ny] != '#'
  • 0 <= nx or nx < n or 0 <= ny or ny < m, a[nx][ny] != '#'
  • 0 <= nx and nx < n and 0 <= ny and ny < m, a[nx][ny] == '#'
  1. (6)(7) 处应填( )。

{{ select(43) }}

  • sumx[c-'A'] + nx,sumy[c-'A'] + ny
  • nx - sumx[c-'A'], ny - sumy[c-'A']
  • sumx[c-'A'], sumy[c-'A']
  • sumx[c-'A'] - nx,sumy[c-'A'] - ny
  1. (8)(9) 处应填( )。

{{ select(44) }}

  • d[nx][ny] == 0, d[x][y]
  • d[nx][ny] == 0, d[x][y] + 1
  • d[nx][ny] != 0, d[x][y] + 1
  • d[nx][ny] != 0, d[x][y] - 1
  1. (10) 处应填( )。

{{ select(45) }}

  • sumx[tx] + sumy[ty]
  • d[tx][ty]
  • d[tx][ty] - 1
  • d[tx][ty] + 1