Wise OA 面试真题解析:即时淘汰投票(Instant-Runoff Voting)获胜者

59次阅读
没有评论

Given voters’ ranked candidate ballots, repeatedly eliminate the candidate with the fewest current votes and transfer those votes to each ballot’s next active preference until one winner remains.

这道题考察的是排名投票(instant-runoff voting / IRV)过程的模拟。每一轮先统计所有仍“存活”候选人的当前票数,找出票数最少的候选人并将其淘汰;随后,对每张投给该候选人的选票,沿着该选票的偏好顺序向后寻找下一位尚未被淘汰的候选人,把票转移过去,继续下一轮统计,直到只剩下一名候选人。实现时通常需要用数组或哈希表维护候选人状态、当前票数,以及每张 ballot 的指针位置;若要高效处理反复转移,常见思路是逐轮扫描或结合优先队列 / 队列结构进行模拟。

正文完
 0