程序博客网 > makemusic finale mac
来源:互联网 发布:makemusic finale mac 编辑:程序博客网 时间:2024/06/06 03:44
/*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>#include <windows.h>using namespace std;typedef unsigned long DWORD;const int P = 1000;int count[P+1] = {0};int main(){DWORD start = GetTickCount();for (int a=1; a<=P; a++)for (int b=a; b<=P-a; b++)for (int c=b; c<=P-b-a; c++){if (a+b<c || a+c<b || b+c<a)break;if (a*a + b*b - c*c == 0 && a+b+c<=P)count[a+b+c]++;}int max = 0;int index = 0;for (int i=1; i<=P; i++)if (count[i])if (count[i] > max){max = count[i];index = i;}cout << index << '/n';DWORD end = GetTickCount();cout <<"the running time = " << end - start << " ms." <<'/n';}