Euler: Integer right triangles
来源:互联网 发布:热力计算软件 编辑:程序博客网 时间:2024/05/21 17:01
If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120. {20,48,52}, {24,45,51}, {30,40,50}
p是三边长度均为整数的直角三角形的周长,当p=120时,存在三种直角三角形。分别是:
{20,48,52}, {24,45,51}, {30,40,50}
For which value of p ≤ 1000, is the number of solutions maximised?
p的范围限定在1000以内,那么p为多少时,具有最多种情况的直角三角形?
思路:从p整数中取出三个数x,y,z,使x>y>z且x+y+z=p。并且要满足y+z>x。
def isRight(x,y,z): if not(x>=y and y >= z): print "should be x>y>z!", str(x),str(y),str(z) return False if x*x == y*y + z*z: return True return Falsedef getnum(p): if p<3 or p>1000: print 'Wrong p' return count = 0 for x in range(p/3, p/2): for y in range((p-x)/2, (p-x)): if x<y: break z = p-x-y if y<z: continue #print "x,y,z=",str(x),str(y),str(z) if isRight(x,y,z): print "x,y,z=",str(x),str(y),str(z) count += 1 print "count for p is ", str(count) return p,countdef main(): #getnum(120) maxcount = 1 maxp = 1 for i in range(3, 1001): tmp_p,tmp_count = getnum(i) if tmp_count > maxcount: maxcount = tmp_count maxp = tmp_p print maxp, maxcountif __name__ == "__main__": main()
0 0
- Euler: Integer right triangles
- Project Euler-Integer right triangles
- Project Euler:Problem 39 Integer right triangles
- Project Euler:Problem 75 Singular integer right triangles
- Project Euler:Problem 91 Right triangles with integer coordinates
- Problem 39—Integer right triangles
- Problem 39 Integer right triangles (数学)
- projecteuler No.91 Right triangles with integer coordinates
- 欧拉工程第39题:Integer right triangles
- Right Triangles
- Right Triangles
- TOJ Right Triangles II
- No_39Integer right triangles
- Codeforces 52B Right Triangles
- Isosceles Right Triangles 坐标暴力枚举
- codeforces 52B - Right Triangles 组合数
- codechef Chef and The Right Triangles 题解
- CodeForces 52 B.Right Triangles(水~)
- java 线程间的通信 pipedOutStream 和PipedInputStream 管道流
- 树链剖分学习笔记
- 调整数组顺序使奇数位于偶数前面
- HDU-1528 Card Game Cheater
- LabelReader分析
- Euler: Integer right triangles
- Lucene学习笔记(二)——搜索,分词
- 精选30道Java笔试题解答
- [leetcode][回溯] Combination Sum
- 非常牛比的网站
- mac 上下载apk包后 如何打开
- TestNG 3 组测试
- C++类内存分布
- 排序应用于链表