CCF GESP 2024年3月认证 C++ 7级
一
单选题
第 1 题
下列关于排序的说法,正确的是( )。
第 2 题
下面的程序属于哪种算法( )。
int pos[8];
void queen(int n) {
for (int i = 0; i < 8; i++) {
pos[n] = i;
bool attacked = false;
for (int j = 0; j < n; j++)
if (pos[n] == pos[j] || pos[n] + n == pos[j] + j || pos[n] - n == pos[j] - j) {
attacked = true;
break;
}
if (attacked)
continue;
if (n == 7) {
return;
} else {
queen(n + 1);
}
}
}
第 3 题
下面有关 C++ 类的说法,错误的是( )。
第 4 题
一个连通的简单无向图,共有 $28$ 条边,则该图至少有( )个顶点。
第 5 题
以下哪个方案不能合理解决或缓解哈希表冲突( )。
第 6 题
已知一颗二叉树的中序遍历序列为:$\{C\ F\ B\ A\ E\ D\ G\}$,后序遍历序列为:$\{F\ C\ B\ E\ G\ D\ A\}$,则下列说法中正确的是( )。
第 7 题
以下关于二叉排序树的说法,正确的是( )。
第 8 题
已知 $x$ 为 double 类型的变量,且值大于 $0$,则下列表达式的值一定大于 $0$ 的是( )。
第 9 题
一个简单有向图有 $10$ 个结点、$30$ 条边。再增加多少条边可以成为完全图。( )
第 10 题
下列选项中,哪个可能是下图的深度优先遍历序列( )。

第 11 题
下面 schedule 函数的时间复杂度为( )。
#include <algorithm>
using namespace std;
struct activity {
int id, start, end;
};
bool compare(activity a, activity b) {
return a.end < b.end;
}
int schedule(int n, activity * p) {
sort(p, p + n, compare);
int cnt = 0, end = 0;
for (int i = 0; i < n; i++) {
if (p[i].start >= end) {
end = p[i].end;
cnt++;
}
}
return cnt;
}
第 12 题
下面
search 函数的平均时间复杂度为( )。int search(int n, int * p, int target) {
int low = 0, high = n;
while (low <= high) {
int middle = (low + high) / 2;
if (target == p[middle]) {
return middle;
} else if (target > p[middle]) {
low = middle + 1;
} else {
high = middle - 1;
}
}
return -1;
}
第 13 题
下面 count_triple 函数的时间复杂度为( )。
int count_triple(int n) {
int cnt = 0;
for (int a = 1; a <= n; a++)
for (int b = a; a + b <= n; b++)
for (int c = b; a + b + c <= n; c++)
if (a * a + b * b == c * c)
cnt++;
return cnt;
}
第 14 题
下面程序的输出为( )。
#include <iostream>
using namespace std;
int down(int n) {
if (n <= 1)
return n;
return down(n - 1) + down(n - 2) + down(n - 3);
}
int main() {
cout << down(6) << endl;
return 0;
}
第 15 题
下面的程序使用邻接矩阵表达的带权无向图,则从顶点 0 到顶点 3 的最短距离为( )。
int weight[4][4] = {
{0, 2, 5, 8},
{2, 0, 1, 7},
{5, 1, 0, 4},
{8, 7, 4, 0}
};
单选题部分已到底了。