EXY-SC-1005
第 496 题
下面的程序使用邻接矩阵表达的带权无向图,则从顶点 0 到顶点 3 的最短距离为( )。
int weight[4][4] = {
{0, 2, 5, 8},
{2, 0, 1, 7},
{5, 1, 0, 4},
{8, 7, 4, 0}
};
语言:
C++
GESP真题
七级
2024.3
单选题号:
15
EXY-SC-1004
第 497 题
下面程序的输出为( )。
#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;
}
语言:
C++
GESP真题
七级
2024.3
单选题号:
14
EXY-SC-1003
第 498 题
下面 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;
}
语言:
C++
GESP真题
七级
2024.3
单选题号:
13
EXY-SC-1002
第 499 题
下面
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;
}
语言:
C++
GESP真题
七级
2024.3
单选题号:
12
EXY-SC-1001
第 500 题
下面 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;
}
语言:
C++
GESP真题
七级
2024.3
单选题号:
11
当前页显示 496 - 500
,共 1260 道单选题