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来可慢的多咯
动态语言永远是那么的飘逸。就似绝世神剑。高手用来心中有剑,低手则走火入魔。
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来可慢的多咯
相关文章推荐
- sublime python3中读取和写入文件时如何解决编码问题
- 用python解决你的实际问题,忘记语言吧
- 使用Python的SymPy库解决数学运算问题
- 解决python selenium3启动不了firefox的问题
- python-13:解决header的问题
- 解决Python中使用mysqldb的一些问题
- Python字符串的encode与decode研究心得乱码问题解决方法
- 解决python大批量读写.doc文件的问题
- Python的Django应用程序解决AJAX跨域访问问题的方法
- Python代码中中文报错问题解决
- Python转码问题的解决方法
- 解决python脚本 在cmd命令行窗口运行时,中文乱码问题
- python 多网站采集,解决编码问题
- Python-selenium-Firefox-chrome-IE问题解决方法
- 在Anaconda中安装(非自带的)python包或者更新已有的python包,解决sklearn无法使用的问题
- python读文件读到windows休止符的问题及解决办法
- 在论坛中找到的几个关于Python的小问题的解决方法
- 经典递归解决汉诺塔问题 python实现
- Python练习(2):递归解决汉诺塔问题
- python datetime.datetime is not JSON serializable 报错问题解决