2 shunfurh shunfurh 于 2017.09.09 18:47 提问

Australian Voting

Australian ballots require that the voter rank the candidates in order of choice. Initially only the first choices are counted and if one candidate receives more than 50% of the vote, that candidate is elected. If no candidate receives more than 50%, all candidates tied for the lowest number of votes are eliminated. Ballots ranking these candidates first are recounted in favour of their highest ranked candidate who has not been eliminated. This process continues [that is, the lowest candidate is eliminated and each ballot is counted in favour of its ranked non-eliminated candidate] until one candidate receives more than 50% of the vote or until all candidates are tied.

Input

The first line of input is an integer n <= 20 indicating the number of candidates. The next n lines consist of the names of the candidates in order. Names may be up to 80 characters in length and may contain any printable characters. The next line contains an integer m <= 1000, and m lines follow; each contains the contents of a ballot. That is, each contains the numbers from 1 to n in some order. The first number indicates the candidate of first choice; the second number indicates candidate of second choice, and so on.

Process to the end of file.

Output

The Output consists of either a single line containing the name of the winner or several lines containing the names of the candidates who tied.

Sample Input

3
John Doe
Jane Smith
Sirhan Sirhan
5
1 2 3
2 1 3
2 3 1
1 2 3
3 1 2

Sample Output

John Doe

1个回答

caozhy
caozhy   Ds   Rxr 2017.09.26 16:34
已采纳
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
UvaOJ 10142 - Australian Voting
裸题。但我看了题解才照着写出来,难点在输入和存储数据部分。模拟选举相对简单容易,只要开个数组记录下淘汰的候选人即可。 学到了一些知识:读入字符串最好用gets;isdigit判断字符是否为数字。 /*Written by Henry.Witt.Joker*/ /*22/05/2012 01:35*/ /*Verdict: Accepted*/ #include #include #incl
UVa 10142 - Australian Voting
题目:澳大利亚选举,有n个候选人m个公民,每个公民对每个候选人有一个期望的优先级,             选举时,先按第一优先级分配选票,得票最少的候选人的投票,将按投票人的优先级,             重新分给留下的候选人,直到某人获得50%或以上的选票,或者剩下的人得票相同,             求选举结果。 分析:模拟。按照上述规则模拟即可,过程有点麻烦。 说明:数据给事
UVA 10142 Australian Voting
Australian ballots require that the voter rank the candidates in order of choice. Initially only the first choices are counted and if one candidate receives more than 50% of the vote, that candidate is
UVa 10142 Australian Voting
#include #include #include char Candidates[20][80]; int Votes[1000][20]; void elect(int num,int voteNum) { int Eliminate[20]; int Count[20]; int left,allvotes; int i,j; int min,max; left = n
10142 - Australian Voting
题目 Time limit: 3.000 seconds pdf题目 解题思路 1.模拟题,一定要小心,把题意搞明白,并且把输入的各种情况都想清楚了再写代码 2.所有的细节都在代码里了,我已经将代码弄的极简洁极易懂了 3.当有人被淘汰出局时,不能把这些票加到现有的候选者上,必须重新计算(不能只修改某些现有的候选者的票数)。道理很简单但却不明显,一个出错的
[uva-10142] Australian Voting (queue&vector)
今天下午到晚上才AC, 遇到了一些问题有: ………………………………
1.6.8 澳大利亚投票 Australian Voting
PC/UVA 110108/10142 模拟。 //author: CHC //First Edit Time: 2014-01-14 14:37 //Last Edit Time: 2014-01-15 22:03 //Filename:1.cpp #include #include #include #include #include #include using namesp
UVA 10142 Australian Voting(模拟)
题意:澳大利亚投票系统要求选民们将所有候选人按愿意选择的程度排序,一张选票就是一个排序。一开始,每张选票的首选项将被统计。若有候选人得票超过50%,他讲直接胜出;否则,所有并列最低的候选人出局,而那些将出局候选人排在第一位的选票将被重新统计为排名最高的未出局候选人。这一筛选过程将持续进行,直到某个候选人得到超过50%的选票,或所有候选人得票相同。 #include #include #inclu
[USACO08DEC]干草出售Hay For Sale——动态规划
[USACO08DEC]干草出售Hay For Sale——动态规划
UVa Problem Solution: 10142 - Australian Voting
I just simulate the electing process. The RT is very slow.Code:/************************************************************************* * Copyright (C) 2008 by liukaipeng