您的位置:首页 > 编程语言 > Python开发

Python解决打靶问题

2008-09-29 13:50 711 查看
原帖见:http://blog.csdn.net/d8111/archive/2008/09/21/2956832.aspx

动态语言永远是那么的飘逸。就似绝世神剑。高手用来心中有剑,低手则走火入魔。

from time import time

def shot(n, remain, his):

"""n goes 0-9"""

if(remain < 0 or remain > (n + 1) * 10):

return;

if(n == 0):

his[0] = remain;

print his

globals()["counter"] += 1

else:

for score in scores:

his
= score;

shot(n - 1, remain - score, his)

if __name__ == "__main__":

scores = range(11)

init = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

counter = 0

begin=time()

shot(9, 90, init)

end=time()

print counter

print end-begin

不过貌似比较可惜的地方是,耗时27.2189998627,比起java来可慢的多咯
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: