`
to_zoe_yang
  • 浏览: 143272 次
  • 性别: Icon_minigender_2
  • 来自: 01
社区版块
存档分类
最新评论

Problem 39

 
阅读更多

问题描述:

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?

 

解决问题:

 

public class Problem39 {

	public static int find_way(int number){
		int count = 0;
		
		for(int c=500; c>0; c--){
			for(int a = c-1; a>(number-c)/2&&a>0; a--){
				int b = number - a - c;
				if(b>0&&b*b+a*a==c*c){
				//	System.out.println("a:"+a+",b:"+b+",c:"+c);
					count++;
				}
			}
		}
		return count;
	}
	
	public static void main(String[] args){
		int max = 0;
		int mark = 0;
		for(int i=1000; i>0; i--){
			int tmp = find_way(i);
			if(tmp>max){
				max =tmp;
				mark = i;
			}
		}
		System.out.println(max+":"+mark);

	}
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics