世界杯小组赛积分所有可能情况
来源:互联网 发布:老白老婆 知乎 编辑:程序博客网 时间:2024/05/01 03:28
学习python中。前两天写了一小段代码,列出所有可能的世界杯小组积分情况,并计算在胜负平等概率时各种积分的出现的概率。
大体思路是用递归得到所有3^6=729种情况,然后利用dict数据类型进行归纳,并进行排序输出。
结果:
[3, 3, 3, 3] : (0.14%)
[4, 4, 4, 3] : (1.10%)
[4, 4, 4, 4] : (0.82%)
[5, 3, 3, 2] : (1.65%)
[5, 4, 3, 2] : (3.29%)
[5, 4, 4, 2] : (3.29%)
[5, 4, 4, 3] : (3.29%)
[5, 5, 2, 2] : (1.65%)
[5, 5, 3, 1] : (1.65%)
[5, 5, 3, 2] : (1.65%)
[5, 5, 4, 1] : (3.29%)
[5, 5, 5, 0] : (0.55%)
[6, 4, 4, 2] : (3.29%)
[6, 4, 4, 3] : (4.94%)
[6, 5, 2, 2] : (1.65%)
[6, 5, 4, 1] : (3.29%)
[6, 6, 3, 3] : (3.29%)
[6, 6, 4, 1] : (3.29%)
[6, 6, 6, 0] : (1.10%)
[7, 3, 2, 2] : (1.65%)
[7, 4, 2, 2] : (3.29%)
[7, 4, 3, 1] : (3.29%)
[7, 4, 3, 2] : (3.29%)
[7, 4, 3, 3] : (3.29%)
[7, 4, 4, 1] : (4.94%)
[7, 5, 2, 1] : (3.29%)
[7, 5, 3, 1] : (3.29%)
[7, 5, 4, 0] : (3.29%)
[7, 6, 2, 1] : (3.29%)
[7, 6, 3, 1] : (3.29%)
[7, 6, 4, 0] : (3.29%)
[7, 7, 1, 1] : (0.82%)
[7, 7, 3, 0] : (1.65%)
[9, 2, 2, 2] : (0.55%)
[9, 3, 3, 3] : (1.10%)
[9, 4, 2, 1] : (3.29%)
[9, 4, 3, 1] : (3.29%)
[9, 4, 4, 0] : (1.65%)
[9, 6, 1, 1] : (1.65%)
[9, 6, 3, 0] : (3.29%)
Total possibilities: 40
代码:
global p
global result
global points
global N
def simu(x, y):
for n in range(0, 3):
points[x][y] = p[n]
points[y][x] = p[2 - n]
if x == N-2 and y == N-1:
temp = [sum(points[i]) for i in range(0, N)]
temp.sort(reverse=True)
if result.has_key(str(temp)):
result[str(temp)] += 1
else:
result[str(temp)] = 1
else:
if (y == N-1):
simu(x+1, x+2)
else:
simu(x, y+1)
if __name__ == "__main__":
N = 4 # there are 4 teams in every group
p = [3, 1, 0] # points when [win, draw, lose]
result = {}
points = [[0] * N for i in range(0, N)] # matrix of points
simu(0, 1) # get all possibilities
matches = 100.0 / (3 ** (N * (N - 1) / 2)) # percents of each possibility
new = []
for k, v in result.items():
new.append("%s : (%2.2f%%)" % (k, v * matches))
print '/n'.join(sorted(new))
print "Total possibilities: %d" % len(result)
- 世界杯小组赛积分所有可能情况
- YTUOJ-世界杯小组赛
- 2014巴西世界杯小组赛赛程
- Tony说世界杯之小组赛预测篇
- YTU 2615: AB编程题--世界杯小组赛
- BST树的所有可能情况
- 2014-6-26世界杯小组赛汇总_16强
- YTU-OJ-Problem E: AB编程题--世界杯小组赛
- Problem E: AB编程题--世界杯小组赛
- hdu1422重温世界杯(小组赛B) 最长非负子序列
- Python分析欧冠小组赛极限情况
- 欧洲冠军杯小组赛积分榜,淘汰赛分组预测
- 给定入栈顺序,输出所有可能出栈情况及所有情况的总数
- ICTCLAS分词之所有可能的组词情况
- 嘻唰唰第六批Problem E: AB编程题--世界杯小组赛
- 世界杯各组积分(更新中)
- 将一个正整数n,拆分成连续的自然数之和,输出所有可能的情况
- 8. String to Integer (atoi) 字符串转为int类型的所有可能情况
- at91sam7x256之IIC(TWI)实验_PCF8563_AT24C02
- c#
- Applications of graph theory to an English rhyming corpus
- log4j 日志服务器_项目实际使用日记
- 总结几种log打印printf函数的宏定义
- 世界杯小组赛积分所有可能情况
- 三星cpu s3c2440 的中断向量表问题
- 第一月工作心得
- mysql输出格式调整
- Informix onstat 命令详解
- android 编译系统阅读与分析(1)-envsetup.sh
- 左值 右值 (转)
- U-Boot-1.2.0源码学习(2)
- Myeclipse "Syntax error,parameterized types are only available if source level is 5.0