python算法学习--待续

几个算法网站

算法可视化网站:https://visualgo.net/en,通过动画展示算法实现过程

程序可视化网站:http://www.pythontutor.com/visualize.html#mode=edit,可视化程序实现过程

LeetCode:https://leetcode.com/,不用介绍了,目前已有中文版

MindHacks:http://mindhacks.cn/,刘未鹏博客

CodeVS: http://codevs.cn/,在线评测平台和算法交流社区

 

 

如果a+b+c = 1000, 且a^2 + b^2 = c^2(a,b,c为自然数),如何求出所有a, b, c可能的组合?

{

a+b+c=1000

a^2 + b^2 = c^2

}

import time
# def condition_solution():
#     start_time = time.time()
#     for a in range(1001):
#         for b in range(1001):
#             for c in range(1001):
#                 if 1000 == a + b + c and a*a + b*b == c*c:
#                     print("a, b, c: %d, %d, %d" % (a, b, c))
#     end_time = time.time()
#     cost = end_time - start_time
#     pri# nt("cost: %f" % cost)
# 
def condition_solution():
    start_time = time.time()
    for a in range(1001):
        for b in range(1001):
                c = 1000 - a - b 
                if 1000 == a + b + c and a*a + b*b == c*c:
                    print("a, b, c: %d, %d, %d" % (a, b, c))
    end_time = time.time()
    cost = end_time - start_time
    print("cost: %f" % cost)

if __name__ == "__main__":
    condition_solution()

 

posted @ 2019-09-16 23:46  何双新  阅读(182)  评论(0编辑  收藏  举报