Companion to the AP-Style MC Practice SetAP 风格选择题练习的解析配套
Unit 3: Algorithms and Programming第 3 单元:算法与编程CSP
Multiple Choice)—— 详细解析Each item restates the prompt and choices, marks the correct letter, and gives a brief justification. Trap distractors are called out where useful.每道题重述题干与选项、标出正确答案字母,并给出简明解析;对容易混淆的干扰项(trap distractor)单独提示。
Consider the following code segment.请考虑以下代码段。
a ← 17 b ← a a ← a MOD 5 b ← b / 5 DISPLAY(a) DISPLAY(b)
What is displayed?显示的结果是什么?
A program stores related readings in a list and then makes a copy.程序将相关读数存储在一个列表(list)中,然后创建其副本。
readings ← [8, 3, 6] backup ← readings REMOVE(readings, 2) INSERT(backup, 2, 9) DISPLAY(readings[2]) DISPLAY(backup[3])
What is displayed?显示的结果是什么?
A label maker takes the first three characters of the string ORCHID, then the last two characters, and concatenates them in that order.标签制作程序先取字符串(string)ORCHID 的前三个字符,再取最后两个字符,并按此顺序拼接。
What string does the label maker produce?标签制作程序生成什么字符串?
A program assigns a category based on a score and absences.程序根据分数和缺勤次数确定类别。
score ← 75 absences ← 2 IF(score ≥ 70) { IF(absences < 2) { DISPLAY(1) } ELSE { DISPLAY(2) } } ELSE { DISPLAY(3) } DISPLAY(score MOD 10)
What is displayed?显示的结果是什么?
Consider the following code segment.请考虑以下代码段。
x ← 4 REPEAT UNTIL(x ≥ 4) { x ← x + 100 } REPEAT UNTIL(x ≥ 11) { x ← x + 3 DISPLAY(x) }
What is displayed?显示的结果是什么?
A robot is on a 5 by 5 grid. Coordinates increase eastward and northward. It starts at (2, 2), facing east. The only black squares are (4, 2) and (3, 4); all other squares are open.机器人(robot)位于一个 5 行 5 列的网格上。坐标向东和向北增大。机器人从 (2, 2) 出发,朝东。只有 (4, 2) 和 (3, 4) 是黑色方格,其余方格均可通行。
REPEAT 3 TIMES { IF(CAN_MOVE(forward)) { MOVE_FORWARD() } ELSE { ROTATE_LEFT() MOVE_FORWARD() } }
Where is the robot, and which direction is it facing, after the code finishes?代码执行结束后,机器人位于何处、朝向哪个方向?
A service admits users whose integer age is from 18 through 65, inclusive.某服务允许整数年龄在 18 至 65 岁之间的用户使用,包含两个端点。
Which two expressions are true exactly for the admitted ages? Select two answers. Select two answers.以下哪两个表达式恰好在年龄符合要求时为真?请选择两个答案。 选择两个答案。
The following code removes selected values from a list.以下代码从列表(list)中删除指定的值。
values ← [4, 2, 2, 5, 2] i ← 1 REPEAT UNTIL(i > LENGTH(values)) { IF(values[i] = 2) { REMOVE(values, i) } ELSE { i ← i + 1 } }
What is the value of values when the loop ends?循环结束时,values 的值是什么?
A school wants to find an ID in a list. The list is currently in the order in which IDs were issued, not in numerical order.学校要在一个列表(list)中查找某个编号。该列表目前按编号发放顺序排列,而不是按数值顺序排列。
Which change makes binary search applicable to this list?进行哪项更改后,可以对该列表使用二分查找(binary search)?
The procedure returns the index of the first list element greater than a limit, or -1 if none exists.该过程(procedure)返回列表中第一个大于指定上限的元素的索引;若不存在这样的元素,则返回 -1。
PROCEDURE FirstAbove(items, limit) { i ← 1 REPEAT UNTIL(i > LENGTH(items)) { IF(items[i] > limit) { RETURN(i) } i ← i + 1 } RETURN(-1) } values ← [2, 5, 9, 7] result ← FirstAbove(values, 6) DISPLAY(result) DISPLAY(LENGTH(values) - result)
What is displayed?显示的结果是什么?
A team uses a documented library procedure to calculate shipping costs. The procedure accepts a weight and returns a cost. The team wants to update its application and avoid duplicating the calculation.某团队使用一个有文档说明的库(library)过程(procedure)计算运费。该过程接收重量并返回费用。团队希望更新应用程序,同时避免重复编写计算代码。
Which two statements are valid? Select two answers. Select two answers.以下哪两个说法正确?请选择两个答案。 选择两个答案。
A simulation represents an event by drawing an integer uniformly with RANDOM(1, 8). The event occurs when the returned value is at most 3.一个模拟(simulation)使用 RANDOM(1, 8) 等概率抽取整数来表示事件。当返回值不大于 3 时,事件发生。
What is the probability that the event occurs on one draw?一次抽取中该事件发生的概率是多少?
A city simulates evacuation times using road capacity and the number of vehicles. Its model assumes every vehicle starts at the same time, although actual departure times vary.某城市利用道路容量和车辆数量模拟疏散时间。模型假设所有车辆同时出发,但实际出发时间各不相同。
Which conclusion about the simulation is best supported?关于该模拟(simulation),以下哪个结论最有依据?
A delivery company must find a low-cost route among many possible routes. An exact algorithm is known to examine an exponentially growing number of candidates as the number of stops increases.一家配送公司需要在众多可能的路线中寻找低成本路线。已知某精确算法检查的候选路线数量会随着停靠点数量增加而呈指数增长。
Which approach is most appropriate when the exact algorithm takes too long on large instances?当精确算法处理大型实例所需时间过长时,哪种方法最合适?
A researcher studies a decision problem that is known to be undecidable.一名研究者正在研究一个已知不可判定的判定问题(decision problem)。
Which statement must be true?以下哪个说法必然正确?