墨尔本大学COMP10001课业解析
题意:
编程实现电子投票自动计数功能,对不同的投票方案有良好的支持性
解析:
背景:
大会选举,每位选民只能支持自己最喜欢的候选人,一人一票,获得最多选票的候选人赢得选举。
方案一:First Past the Post
实现first_past_the_post(votes)函数,参数votes是一个存储选票信息的列表,是一系列代表候选人名字的字符。
考虑用遍历列表的方法分别统计每个候选人的频率,比较大小后返回频率最高者的名字;存在最高得票的多个候选人票数一样的情况,返回 “tie”。
方案二:Second Preference
实现second_preference(votes)函数,参数votes是一个存储
选票信息的二重列表。此方案用来解决方案一中,胜出者选票<=50%的情况。首先按第一志愿统计候选人频率,最高得票不过半,删掉第一志愿中得票最低的候选人(有多个按候选人首字母次序删除较前的候选人),并且统计剩余候选人得票数(第一志愿+第二志愿),返回最高者名字,若有多个返回 “tie”。
方案三:Multiple Preferences
实现multiple_preferences(votes)函数,参数votes是一个存储选票信息的二重列表。方案二只进行一轮,方案三是多轮的改进版。样例中采取5志愿投票,类似方案二的方法进行。
涉及知识点:
python 列表,二重列表,循环
微信号:g19963812037
pdf全文
Project 1
21 August 2019
eVoting
• As A/Prof Teague mentioned in her guest lecture – a major challenge is how to run elections online
• Imagine you are a programmer for the Australian Electoral Commission, and you have been asked
to automate the counting of electronic votes. Can you write programs to automate vote counting for
different voting schemes?
Background
We consider an election where multiple candidates are running to be the representative of a given el
ectorate.Each voter lodges their vote for their preferred candidate(s).The candidate with the most vot
es wins the electorate.
• Example of a simple voting scheme Candidates: “chris”, “marion”, “nic”
Number of votes for each candidate:
“chris” : 121, “marion” : 399, “nic” : 180
Winning candidate: “marion”
Background
A major challenge in voting schemes is how to reflect the preferences of voters, so that the winning c
andidate has the support of the majority i.e. ideally > 50% of the votes.
We will consider three different voting schemes:
• First past the post (used in the UK, US, Survivor)
• Second preference
• Multiple preferences (used in Australia)
First Past the Post
• This is the simplest voting scheme.
• There is a given list of candidates.
• Each voter picks their preferred candidate.
• We count the number of votes for each candidate.
• The candidate with the most votes wins.
• Example of a simple voting scheme
Candidates: “chris”, “marion”, “nic”
Number of votes for each candidate:
“chris” : 121, “marion” : 399, “nic” : 180
Winning candidate: “marion”
First Past the Post
• Example of a simple voting scheme
Candidates: “chris”, “marion”, “nic”
Consider an electorate with 9 voters
List of votes:[“chris”, “marion”, “marion”, “nic”, “marion”, “nic”, “nic”, “chris”, “marion”]
Number of votes for each candidate:“chris” : 2, “marion” : 4, “nic” : 3
Winning candidate: “marion”
• Note: winner might not have an absolute majority.i.e., less than 50% of the electorate voted for the winner
• Note: an election can result in a tie, where two or more candidates have the highest number of votes
Candidates: “chris”, “marion”, “nic”
Consider an electorate with 9 voters
Votes:[“chris”, “nic”, “marion”, “nic”, “chris”, “nic”, “nic”, “chris”, “chris”]
Number of votes for each candidate:“chris” : 4, “m