当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2952:Election

题目描述

Given the voting preferences of a population of M people, you are to determine the winner of an election among N candidates, numbered 1, …, N. For this problem, the M people are partitioned into G “groups” where all members within a group have the same voting preferences. The candidate preferences for a group are specified by listing candidates from most preferred to least preferred. Election results are determined by an instant-runoff voting procedure.

In this method, the first choices of the M people in the population are counted and the least popular candidate is eliminated. In the event of a tie, the highest-numbered candidate is eliminated. Then, the eliminated candidate is removed from the preference list of all M individuals in the population, and again the least popular candidate is eliminated. This process repeats until only a single candidate is left.

输入解释

The input test file will contain multiple test cases. Each input test case begins with a single line containing the integers G and N where 2 ≤ N ≤ 5 and 1 ≤ G ≤ 20. The next G lines are of the format “Mi ai1 ai2aiN” where 1 ≤ Mi ≤ 20 and ai1, …, aiN is a permutation of the integers 1, …, N. Mi is the number of individuals in the ith group, and ai1, …, aiN is the ordering of the N candidates from most preferred to least preferred for the ith group. The end-of-file is marked by a test case with G = N = 0 and should not be processed.

输出解释

For each input case, the program should print the winner of the election on a single line.

输入样例
3 4
10 1 4 2 3
15 3 2 1 4
12 4 3 2 1
3 2
10 1 2
10 1 2
20 2 1
0 0
输出样例
4
1

该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 Stanford Local 2004

源链接: POJ-2952

最后修改于 2020-10-29T06:48:27+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536