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?

题目大意:

如果p是一个直角三角形的周长,三角形的三边长{a,b,c}都是整数。对于p = 120一共有三组解:

{20,48,52}, {24,45,51}, {30,40,50}

对于1000以下的p中,哪一个能够产生最多的解?

#include <stdio.h>

int count(int p)
{
int a, b, c, n, p1, p2;
n = ;
p1 = p / ;
p2 = p / ;
for(a = ; a < p1; a++) {
for(b = p2 - a; b < p2; b++) {
c = p - a - b;
if(a * a + b * b == c * c) {
n++;
}
}
}
return n;
} int main()
{
int i, max, t, k;
max = ;
for(i = ; i < ; i++) {
t = count(i);
if(t > max) {
max = t;
k = i;
}
}
printf("%d\n",k);
return ;
}
Answer:
840

(Problem 39)Integer right triangles的更多相关文章

  1. Project Euler:Problem 39 Integer right triangles

    If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exact ...

  2. Project Euler 39 Integer right triangles( 素勾股数 )

    题意:若三边长 { a , b , c } 均为整数的直角三角形周长为 p ,当 p = 120 时,恰好存在三个不同的解:{ 20 , 48 , 52 } , { 24 , 45 , 51 } , ...

  3. Problem D: Integer Inquiry

    Problem D: Integer InquiryTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 41 Solved: 12[Submit][Status ...

  4. Project Euler 75:Singular integer right triangles

    题目链接 原题: It turns out that 12 cm is the smallest length of wire that can be bent to form an integer ...

  5. Project Euler 75: Singular integer right triangles

    题目链接 思路: 勾股数组,又称毕达格拉斯三元组. 公式:a = s*t b = (s^2 - t^2) / 2 c = (s^2 + t^2) / 2 s > t >=1 且为互质的奇数 ...

  6. EularProject 39:给周长推断构成直角三角形个数

    华电北风吹 天津大学认知计算与应用重点实验室 完毕日期:2015/7/30 Integer right triangles Problem 39 If p is the perimeter of a ...

  7. Leetcode 题目整理-3 Palindrome Number & Roman to Integer

    9. Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. clic ...

  8. 65. Reverse Integer && Palindrome Number

    Reverse Integer Reverse digits of an integer. Example1: x =  123, return  321 Example2: x = -123, re ...

  9. SGU 248. Integer Linear Programming( 背包dp )

    看了半天...发现就是个背包...然后就不打算敲了. 看了一眼forum..顿时吓傻..其他人用了gcd啊什么的各种奇怪的东西..然后还是敲了个背包结果就AC了= =既然写了代码就扔上来吧... -- ...

随机推荐

  1. C# GridView弹出窗口新增行 删除行

    <%@ Page Language="C#" AutoEventWireup="true" EnableViewState="true" ...

  2. C++_转换转子(4种)

    static_cast const_cast dynamic_cast

  3. IOS优秀博客

    链接地址:http://www.cnblogs.com/keithmoring/p/4155264.html 剑心的博客信息量很大,适合查阅和入门,学习完,你差不多就可以出山了,还有作为复习IOS的一 ...

  4. Euclid gcd规则的证明

    Euclid 规则:如果x和y都是正整数,而且x>=y,那么gcd(x,y)=gcd(x mod y, y) 假设x和y的gcd为a,那么必然有 x=a*n1 y=a*n2(gcd(n1,n2) ...

  5. C#正则提取HTML中img的url值

    /// <summary> /// 取得HTML中所有图片的 URL. /// </summary> /// <param name="sHtmlText&qu ...

  6. jQuery滚动广告 解决子div绝对定位与父div重叠引起的闪烁问题

    这两天做了一个滚动广告栏的demo 功能有自动轮播 左右箭头移动 导航点选中图片移动效果 模仿的是新浪体育的广告 最难的问题就是子div绝对定位于父div 鼠标移入子div 系统会判定鼠标移出了父di ...

  7. C语言struct类型

    在实际问题中,一组数据往往具有不同的数据类型.例如, 在学生登记表中,姓名应为字符型:学号可为整型或字符型: 年龄应为整型:性别应为字符型:成绩可为整型或实型. 显然不能用一个数组来存放这一组数据. ...

  8. linux 关于动态库的知识

    问题起缘于编译一个程序时,使用glib2-2.28.8的动态库,而系统自带的是glib2-2.22.5 不想升级系统的glib2库,而使用程序自带库文件的方式加载(类似windows系统,优先加载当前 ...

  9. 手把手教程 Surface如何进行系统恢复?

    手把手教程 Surface如何进行系统恢复? 2015-01-29 05:53:00  [  中关村在线 原创  ]   作者: 周博林 |  责编:周博林 收藏文章 分享到 评论(10) Windo ...

  10. ReentrantLock(重入锁)以及公平性

    ReentrantLock(重入锁)以及公平性 标签(空格分隔): java NIO 如果在绝对时间上,先对锁进行获取的请求一定被先满足,那么这个锁是公平的,反之,是不公平的,也就是说等待时间最长的线 ...