在游戏石英石有一个棋盘,包括友好的和敌人的奴才,和两个英雄-你和敌人的。
为了概括和简化,我们将假设该轮到你了,对手有0-7个在棋盘上具有给定生命值的仆从,并且处于H生命点。我们将完全忽略董事会的角色。
现在,我们将投出一个增压版本的奥术导弹。此技能射击一个随机敌人(从所有活着的奴才和英雄中一致选择),造成1点伤害,重复A次。请注意,如果目标死亡(降为0生命),则无法再次命中。
给定H,A和L的名单,其中包含了仆从的健康值,输出的概率作为一个百分比精确到小数点后的2位英雄死亡,或两个英雄死亡,或每个仆从死亡(清除董事会)。
一些逻辑上推导出的例子:
H: 30, A: 2, L: [1, 1]
We have no chance of killing our opponent here. To clear the board, both shots
must hit a minion. The first shot has a 2/3 chance of hitting a minion, then
that minion dies. The second shot has a 1/2 chance. The probability of clearing
the board or killing our opponent is thus 2/6 = 33.33%.
H: 2, A: 3, L: [9, 3, 4, 1, 9]
We have no chance of clearing the board here. 2/3 shots must hit the hero. However,
if any of the shots hit the 1 health minion, it dies, increasing the odds for
future shots.
4/6 the first shot hits a health minion. The next two shots must hit the hero,
for a total probability of 4/6 * 1/6 * 1/6.
1/6 the first shot hits the 1 health minion and it dies. The next two shots must
hit the hero, for a total probability of 1/6 * 1/5 * 1/5.
1/6 the first shot hits the hero. Then there are three options again:
1/6 the second shot hits the hero.
4/6 the second shot hits a healthy minion. The last shot must hit 1/6.
1/6 the second shot hits the 1 health minion. The last shot must hit 1/5.
This last option gives a probability of 1/6 * (1/6 + 4/6 * 1/6 + 1/(5*6)). The
total probability is the chance of any of these scenarios happening, or:
4/6 * 1/6 * 1/6 + 1/(6*5*5) + 1/6 * (1/6 + 4/6 * 1/6 + 1/(5*6)) = 7.70%如你所见,事情很快就变得复杂起来.祝好运!
你的分数是你回答的代码的字节数。如果您的代码精确地计算概率,而不是模拟板子,则将分数减半。最低分获胜。
发布于 2015-07-25 09:45:51
L_,*lbJ*FeCbsm*hd/JedbM?&hHstH?GymgtG-XdKH_1_!dlH,01,TT*100cFghQstQ这符合奖金,即使我必须手动实现任意的精确理据。
(我希望Pyth5已经是一件事了)。
从STDIN输入的A, H, L格式
修正为输出百分比。百分比是尽可能精确的,因为使用整数的数学直到最后一步。
在高层次上,第一段L_,*lbJ*FeCbsm*hd/Jedb是一个辅助函数,它以两个元素列表的形式接受一个理性主义列表,并将它们的平均值输出为一个(未缩减的) rational。
第二部分,M?&hHstH?GymgtG-XdKH_1_!dlH,01,TT,重新计算获胜的概率。
第三段,cFghQstQ格式化输入以适应函数并执行最后的除法。
在第二个示例中,最后的未还原的2-tuple太长,无法在屏幕上显示:
[83158592487544376524800000000000000000000, 1079462498636393349120000000000000000000000]幸运的是,Pyth确实有任意精度的整数。
发布于 2015-07-24 11:25:03
这里有一个ruby解决方案,它使用递归的强大功能精确地计算答案(然后按照指定的方式截断答案)。您可以使用g函数在irb中运行它:
require 'rational'
def c(h, a, l)
l=l.reject { |m| m == 0 }
return 1.to_r if l.empty? ||h==0
return 0.to_r if a==0
a-=1
n=[c(h-1, a, l), *((0..l.length-1).map { |i| nl = l.dup;nl[i]-=1;c(h, a, nl)})]
n.inject(:+)/n.length
end
def g(h, a, l)
puts "%.2f%%" % (c(h.to_r, a.to_r, l.map(&:to_r)) * 100)
end示例输出:
> g 30, 2, [1,1]
33.33%
> g 2, 3, [9,3,4,1,9]
7.70%https://codegolf.stackexchange.com/questions/53688
复制相似问题