首页 > 其他 > 详细

Project Euler:Problem 39 Integer right triangles

时间:2015-10-06 10:16:25      阅读:218      评论:0      收藏:0      [点我收藏+]

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}

For which value of p ≤ 1000, is the number of solutions maximised?



#include <iostream>
using namespace std;


int main()
{
	int ans = 0;
	int maxp = 0;
	for (int i = 12; i <= 1000; i++)
	{
		int maxc = 0;
		for (int a = 1; a < i; a++)
		{
			for (int b = 1; b < a; b++)
			{
				int c = i - a - b;
				if (c < 0)
					break;
				if (a*a + b*b == c*c)
					maxc++;
			}
		}
		if (maxc>ans)
		{
			ans = maxc;
			maxp = i;
		}

	}
	cout << ans << " " << maxp << endl;
	system("pause");
	return 0;
}


版权声明:本文博主原创文章,博客,未经同意不得转载。

Project Euler:Problem 39 Integer right triangles

原文:http://www.cnblogs.com/gcczhongduan/p/4856731.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!