林老师 · 客观题题库 · CSP-S 2024 · 提高级第一轮真题

CSP-S 2024 · 提高级第一轮真题

2024 CCF CSP-S(提高级)第一轮 · 客观题真题 · 满分 100 分
真题
复刻
试卷编号OBJ-848975
题目总数20 题 · 100.0 分
试卷类型客观题
考生须知:
① 本卷为客观题单卷,合计 20 题 · 100.0 分,全部为客观题;
② 试卷右上角设有 「提交答卷」「重置考试」 按钮,提交后系统自动判分并显示答题正确情况,请确认全部作答后再行提交;
③ 试卷不显示答案,提交后方可查看每题作答与正确答案的对照;
④ 答卷进度会保留在本地缓存中,刷新或再次打开仍可继续作答;
⑤ 本卷仅供学生练习使用;请勿用于其他用途;题面有问题请联系:i64coder@163.com。

判 分 报 告

0 / 100.0 分
0
答 对 · 得 0
0
答 错 · 失 0
当前筛选下没有题目

客 观 题

20 QUESTIONS · 2 POINTS EACH
第 1 题 单选 未作答

Linux 系统中,如果你想显示当前工作目录的路径,应该使用哪个命令?( )

(2 分)
CSP-S 2024 · 单选 第1题 | 知识点 文件与目录、文件类型与扩展名
第 2 题 单选 未作答

假设一个长度为 nn 的整数数组中每个元素值互不相同,且这个数组是无序的。要找到这个数组中最大元素的时间复杂度是多少?( )

(2 分)
CSP-S 2024 · 单选 第2题 | 知识点 剪枝、排序稳定性
第 3 题 单选 未作答

在 C++ 中,以下哪个函数调用会造成栈溢出?( )

(2 分)
CSP-S 2024 · 单选 第3题 | 知识点 三目运算、归并排序、栈
第 4 题 单选 未作答

在一场比赛中,有 1010 名选手参加,前三名将获得金、银、铜牌。若不允许并列,且每名选手只能获得一枚奖牌,则不同的颁奖方式共有多少种?

(2 分)
CSP-S 2024 · 单选 第4题 | 知识点 插空法、威尔逊定理
第 5 题 单选 未作答

下面哪个数据结构最适合实现先进先出(FIFO)的功能?

(2 分)
CSP-S 2024 · 单选 第5题 | 知识点 双端队列、栈
第 6 题 单选 未作答

已知 f(1)=1f(1) = 1,且对于 n2n \ge 2f(n)=f(n1)+f(n/2)f(n) = f(n - 1) + f(\lfloor n/2 \rfloor),则 f(4)f(4) 的值为( )。

(2 分)
CSP-S 2024 · 单选 第6题 | 知识点 堆排序、归并排序
第 7 题 单选 未作答

假设有一个包含 nn 个顶点的无向图,且该图是欧拉图。以下关于该图的描述中哪一项不一定正确?( )

(2 分)
CSP-S 2024 · 单选 第7题 | 知识点 邻接矩阵、邻接矩阵
第 8 题 单选 未作答

对数组进行二分查找的过程中,以下哪个条件必须满足?( )

(2 分)
CSP-S 2024 · 单选 第8题 | 知识点 剪枝、数组越界
第 9 题 单选 未作答

考虑一个自然数 nn 以及一个模数 mm,你需要计算 nn 的逆元(即 nn 在模 mm 意义下的乘法逆元)。下列哪种算法最为适合?

(2 分)
CSP-S 2024 · 单选 第9题 | 知识点 分治、最大公约数
第 10 题 单选 未作答

在设计一个哈希表时,为了减少冲突,需要使用适当的哈希函数和冲突解决策略。已知某哈希表中有 nn 个键值对,表的装载因子为 aa0<a10 < a \le 1)。在使用开放地址法解决冲突的过程中,最坏情况下查找一个元素的时间复杂度为?

(2 分)
CSP-S 2024 · 单选 第10题 | 知识点 堆、排序稳定性
第 11 题 单选 未作答

假设有一棵 hh 层的完全二叉树,该树最多包含多少个结点?

(2 分)
CSP-S 2024 · 单选 第11题 | 知识点 完全二叉树、二叉树性质
第 12 题 单选 未作答

设有一个有 1010 个顶点的完全图,每两个顶点之间都有一条边。有多少个长度为 44 的环?

(2 分)
CSP-S 2024 · 单选 第12题 | 知识点 排列、邻接矩阵
第 13 题 单选 未作答

对于一个整数 nn,定义 f(n)f(n)nn 的各位数字之和。问使 f(f(x))=10f(f(x)) = 10 的最小自然数 xx 是多少?

(2 分)
CSP-S 2024 · 单选 第13题 | 知识点 初等代数、模拟
第 14 题 单选 未作答

设有一个长度为 nn0101 字符串,其中有 kk11。每次操作可以交换相邻两个字符。在最坏情况下将这 kk11 移到字符串最右边所需要的交换次数是多少?

(2 分)
CSP-S 2024 · 单选 第14题 | 知识点 威尔逊定理、排列
第 15 题 单选 未作答

如图是一张包含 77 个顶点的有向图。如果要删除其中一些边,使得从节点 11 到节点 77 没有可行路径,且删除的边数最少,请问总共有多少种可行的删除边的集合?

(2 分)
CSP-S 2024 · 单选 第15题 | 知识点 邻接矩阵、冒泡排序
第 16~20 题 阅读程序 (共 11.5 分) 未作答

1  #include <iostream>
2  using namespace std;
3 
4  const int N = 1000;
5  int c[N];
6 
7  int logic(int x, int y) {
8      return (x & y) ^ ((x ^ y) | (~x & y));
9  }
10  void generate(int a, int b, int *c) {
11      for (int i = 0; i < b; i++) {
12          c[i] = logic(a, i) % (b + 1);
13      }
14  }
15  void recursion(int depth, int *arr, int size) {
16      if (depth <= 0 || size <= 1) return;
17      int pivot = arr[0];
18      int i = 0, j = size - 1;
19      while (i <= j) {
20          while (arr[i] < pivot) i++;
21          while (arr[j] > pivot) j--;
22          if (i <= j) {
23              int temp = arr[i];
24              arr[i] = arr[j];
25              arr[j] = temp;
26              i++; j--;
27          }
28      }
29      recursion(depth - 1, arr, j + 1);
30      recursion(depth - 1, arr + i, size - i);
31  }
32 
33  int main() {
34      int a, b, d;
35      cin >> a >> b >> d;
36      generate(a, b, c);
37      recursion(d, c, b);
38      for (int i = 0; i < b; ++i) cout << c[i] << " ";
39      cout << endl;
40  }

16.

1000db1000 \ge d \ge b 时,输出的序列是有序的。

(1.5 分)
17.

当输入 5 5 1 时,输出为 1 1 5 5 5

(1.5 分)
18.

假设数组 c 长度无限制,该程序所实现的算法的时间复杂度是 O(b)O(b) 的。

(1.5 分)
19.

函数 int logic(int x, int y) 的功能是( )。

(3 分)
20.

当输入为 10 100 100 时,输出的第 100100 个数是( )。

(4 分)
CSP-S 2024 · 阅读程序 第16-20题 | 知识点 广度优先搜索、广度优先搜索、广度优先搜索、双指针
第 21~26 题 阅读程序 (共 14 分) 未作答

1   #include <iostream>
2  #include <string>
3  using namespace std;
4 
5  const int P = 998244353, N = 1e4+10, M = 20;
6  int n, m;
7  string s;
8  int dp[1<<M];
9 
10  int solve() {
11      dp[0] = 1;
12      for (int i = 0; i < n; ++i) {
13          for (int j = (1<<(m-1))-1; j >= 0; --j) {
14              int k = (j<<1)|(s[i]-'0');
15              if (j != 0 || s[i] == '1')
16                  dp[k] = (dp[k] + dp[j]) % P;
17          }
18      }
19      int ans = 0;
20      for (int i = 0; i < (1<<m); ++i) {
21          ans = (ans + 1ll * i * dp[i]) % P;
22      }
23      return ans;
24  }
25  int solve2() {
26      int ans = 0;
27      for (int i = 0; i < (1<<n); ++i) {
28          int cnt = 0;
29          int num = 0;
30          for (int j = 0; j < n; ++j) {
31              if (i & (1<<j)) {
32                  num = num * 2 + (s[j]-'0');
33                  cnt++;
34              }
35          }
36          if (cnt <= m) (ans += num) %= P;
37      }
38      return ans;
39  }
40 
41  int main() {
42      cin >> n >> m;
43      cin >> s;
44      if (n <= 20) {
45          cout << solve2() << endl;
46      }
47      cout << solve() << endl;
48      return 0;
49  }

假设输入的字符串 ss 是包含 nn 个字符的 0101 串,完成下面的判断题和单选题。

21.

假设数组 dp 长度无限制,函数 solve() 所实现的算法的时间复杂度是 O(n2m)O(n \cdot 2^m)

(1.5 分)
22.

输入 11 2 10000000001 时,程序输出两个数 32322323。( )

(1.5 分)
23.

n10n \leq 10 时,solve() 的返回值始终小于 4104^{10}。( )

(2 分)
24.

n=10n = 10m=10m = 10 时,有多少种输入使得两行的结果完全一致?( )

(3 分)
25.

n6n \leq 6 时,solve() 的最大可能返回值为( )

(3 分)
26.

假设 n=8n = 8m=8m = 8solve()solve2() 的返回值的最大可能差值为( )

(3 分)
CSP-S 2024 · 阅读程序 第21-26题 | 知识点 广度优先搜索、广度优先搜索、广度优先搜索、双指针
第 27~32 题 阅读程序 (共 14.5 分) 未作答

1   #include <iostream>
2  #include <cstring>
3  #include <algorithm>
4  using namespace std;
5 
6  const int maxn = 1000000+5;
7  const int P1 = 998244353, P2 = 1000000007;
8  const int B1 = 2, B2 = 31;
9  const int K1 = 0, K2 = 13;
10 
11  typedef long long ll;
12 
13  int n;
14  bool p[maxn];
15  int p1[maxn], p2[maxn];
16 
17  struct H {
18      int h1, h2, l;
19      H(bool b = false) {
20          h1 = b + K1;
21          h2 = b + K2;
22          l = 1;
23      }
24      H operator + (const H & h) const {
25          H hh;
26          hh.l = l + h.l;
27          hh.h1 = (1ll * h1 * p1[h.l] + h.h1) % P1;
28          hh.h2 = (1ll * h2 * p2[h.l] + h.h2) % P2;
29          return hh;
30      }
31      bool operator == (const H & h) const {
32          return l == h.l && h1 == h.h1 && h2 == h.h2;
33      }
34      bool operator < (const H & h) const {
35          if (l != h.l) return l < h.l;
36          else if (h1 != h.h1) return h1 < h.h1;
37          else return h2 < h.h2;
38      }
39  } h[maxn];
40 
41  void init() {
42      memset(p, 1, sizeof(p));
43      p[0] = p[1] = false;
44      p1[0] = p2[0] = 1;
45      for (int i = 1; i <= n; ++i) {
46          p1[i] = (1ll * B1 * p1[i-1]) % P1;
47          p2[i] = (1ll * B2 * p2[i-1]) % P2;
48          if (!p[i]) continue;
49          for (int j = 2 * i; j <= n; j += i) {
50              p[j] = false;
51          }
52      }
53  }
54 
55  int solve() {
56      for (int i = n; i; --i) {
57          h[i] = H(p[i]);
58          if (2 * i + 1 <= n) {
59              h[i] = h[2 * i] + h[i] + h[2 * i + 1];
60          } else if (2 * i <= n) {
61              h[i] = h[2 * i] + h[i];
62          }
63      }
64      cout << h[1].h1 << endl;
65      sort(h + 1, h + n + 1);
66      int m = unique(h + 1, h + n + 1) - (h + 1);
67      return m;
68  }
69 
70  int main() {
71      cin >> n;
72      init();
73      cout << solve() << endl;
74  }

27.

假设程序运行前能自动将 maxn 改为 n + 1,所实现的算法的时间复杂度是 O(nlogn)O(n \log n)。( )

(1.5 分)
28.

时间开销的瓶颈是 init() 函数。( )

(1.5 分)
29.

若修改常数 B1K1 的值,该程序可能会输出不同的结果。( )

(1.5 分)
30.

solve() 函数中,h[] 的合并顺序可以看作是:( )

(3 分)
31.

输入 10,输出的第一行是?( )

(3 分)
32.

输入 16,输出的第二行是?( )

(4 分)
CSP-S 2024 · 阅读程序 第27-32题 | 知识点 广度优先搜索、广度优先搜索、双指针、二叉树性质
第 33~37 题 完善程序 (共 15 分) 未作答

(序列合并)问题:有两个长度为 NN 的单调不降序列 AABB,序列的每个元素都是小于 10910^9 的非负整数。在 AABB 中各取一个数相加可以得到 N2N^2 个和,求其中第 KK 小的和。上述参数满足 N105N \le 10^51KN21 \le K \le N^2

1  #include <iostream>
2  using namespace std;
3 
4  const int maxn = 100005;
5 
6  int n;
7  long long k;
8  int a[maxn], b[maxn];
9 
10  int* upper_bound(int *a, int *an, int ai) {
11      int l = 0, r = ①;
12      while (l < r) {
13          int mid = (l+r)>>1;
14          if (②) {
15              r = mid;
16          } else {
17              l = mid + 1;
18          }
19      }
20      return ③;
21  }
22 
23  long long get_rank(int sum) {
24      long long rank = 0;
25      for (int i = 0; i < n; ++i) {
26          rank += upper_bound(b, b+n, sum - a[i]) - b;
27      }
28      return rank;
29  }
30 
31  int solve() {
32      int l = 0, r = ④;
33      while (l < r) {
34          int mid = ((long long)l+r)>>1;
35          if (⑤) {
36              l = mid + 1;
37          } else {
38              r = mid;
39          }
40      }
41      return l;
42  }
43 
44  int main() {
45      cin >> n >> k;
46      for (int i = 0; i < n; ++i) cin >> a[i];
47      for (int i = 0; i < n; ++i) cin >> b[i];
48      cout << solve() << endl;
49  }

33.

①处应填()

(3 分)
34.

②处应填()

(3 分)
35.

③处应填()

(3 分)
36.

④处应填()

(3 分)
37.

⑤处应填()

(3 分)
CSP-S 2024 · 完善程序 第33-37题 | 知识点 倍增、剪枝、位异或、数组越界
第 38~42 题 完善程序 (共 15 分) 未作答

(次短路)已知一个有 nn 个点、mm 条边的有向图 GG,并且给定图中的两个点 sstt,求次短路(长度严格大于最短路的最短路径)。如果不存在,输出一行 -1;如果存在,输出两行,第一行表示次短路的长度,第二行表示次短路的一个方案。

1  #include <cstdio>
2  #include <queue>
3  #include <utility>
4  #include <cstring>
5  using namespace std;
6 
7  const int maxn = 2e5+10, maxm = 1e6+10, inf = 522133279;
8 
9  int n, m, s, t;
10  int head[maxn], nxt[maxm], to[maxm], w[maxm], tot = 1;
11  int dis[maxn<<1], *dis2;
12  int pre[maxn<<1], *pre2;
13  bool vis[maxn<<1];
14 
15  void add(int a, int b, int c) {
16      ++tot;
17      nxt[tot] = head[a];
18      to[tot] = b;
19      w[tot] = c;
20      head[a] = tot;
21  }
22 
23  bool upd(int a, int b, int d, priority_queue<pair<int, int>> &q) {
24      if (d >= dis[b]) return false;
25      if (b < n) ①;
26      q.push(②);
27      dis[b] = d;
28      pre[b] = a;
29      return true;
30  }
31 
32  void solve() {
33      priority_queue<pair<int, int> > q;
34      q.push(make_pair(0, s));
35      memset(dis, ③, sizeof(dis));
36      memset(pre, -1, sizeof(pre));
37      dis2 = dis+n;
38      pre2 = pre+n;
39      dis[s] = 0;
40      while (!q.empty()) {
41          int aa = q.top().second; q.pop();
42          if (vis[aa]) continue;
43          vis[aa] = true;
44          int a = aa % n;
45          for (int e = head[a]; e; e = nxt[e]) {
46              int b = to[e], c = w[e];
47              if (aa < n) {
48                  if (!upd(a, b, dis[a]+c, q))
49                      ④;
50              } else {
51                  upd(n+a, n+b, dis2[a]+c, q);
52              }
53          }
54      }
55  }
56 
57  void out(int a) {
58      if (a != s) {
59          if (a < n) out(pre[a]);
60          else out(⑤);
61      }
62      printf("%d%c", a%n+1, " \n"[a == n+t]);
63  }
64 
65  int main() {
66      scanf("%d%d%d%d", &n, &m, &s, &t);
67      s--, t--;
68      for (int i = 0; i < m; ++i) {
69          int a, b, c;
70          scanf("%d%d%d", &a, &b, &c);
71          add(a-1, b-1, c);
72      }
73      solve();
74      if (dis2[t] == inf) puts("-1");
75      else {
76          printf("%d\n", dis2[t]);
77          out(n+t);
78      }
79  }

38.

①处应填().

(3 分)
39.

②处应填()

(3 分)
40.

③处应填()

(3 分)
41.

④处应填()

(3 分)
42.

⑤处应填()

(3 分)
CSP-S 2024 · 完善程序 第38-42题 | 知识点 递推、回溯、邻接表、邻接矩阵