墨尔本大学COMP10001课业解析

本文介绍了墨尔本大学COMP10001课程中的电子投票系统设计,涵盖First Past the Post、Second Preference和Multiple Preferences三种投票方案。每个方案详细解释了计票规则,并提供了示例代码解析,旨在实现自动化计票功能,确保选举公正性。
摘要由CSDN通过智能技术生成

墨尔本大学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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值