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. 剑指offer第10题

    import java.util.Scanner; /* 前两种方法是看最低为是不是为1,不为1则向右移动. 第一种只能对正整数有效,对负数不行,因为负数用的是补码,最高外符号位为1,最后右移动,肯定 ...

  2. jsp 配置MySQL服务器 以及数据的插入和读取

    不多说,直接上代码.百度上面也是一大堆,大家多问百度就行. 在利用JDBC访问数据库过程中,主要涉及三种资源:对数据库的连接的连接对象Connection,SQL语句对象 Statement,访问结果 ...

  3. php中禁止非法调用和硬路径引入文件的方法

    php中禁止非法调用和硬路径引入文件的方法 在php中有一些公共的文件为了方便,我们会做一个公共文件,让不用的文件共同调用.为了禁止公共文件被非常单独调用,可以在文件上做一个常量,禁止非常调用:在公共 ...

  4. nginx-configure执行大致流程

    1,configure 命令行参数处理 2,初始化各种文件路径 3,分析源码结构 4,生成编译过程中所需路径 5,准备 .h,.err等编译所需文件 6,写入命令行参数 7,检测环境(系统,编译器,第 ...

  5. Xcode Coule not launch "aaa" press launch failed:timed out waiting for app launch

    遇见这个问题 可能是 由于 runapp 的时候设置里面 设置为release了. 解决办法是:见图 build configuration 设置成 debug 状态就OK了. 要是上面的不行就试一下 ...

  6. 13.java.lang.NoSuchFiledException

    java.lang.NoSuchFiledException 方法不存在异常 当程序试图通过反射来创建对象,访问(修改或读取)某个filed,但是该filed不存在就会引发异常

  7. 製程能力介紹(SPC introduction) ─ Cp之製程能力解釋

    Cp之製程能力解釋 從常態分配的特性來看,在群體中 ±3σ(標準差) 之範圍內的值,應包含群體全部的 99.73%.也就是說,若以 6σ為單位,就可以代表整個分布的範圍,但是有 0.27% (2700 ...

  8. 深入Blocks分析

    1.简介 从iOS4开始,苹果引入了这个C语言的扩充功能"Blocks",在一些特定的场景下也是一把利刃.我前面一篇博客中初步介绍了Blocks这个东西,主要是语法的介绍(< ...

  9. iOS中Blocks的介绍

    1. 什么是Blocks Blocks是C语言的扩充功能.如果用一句话来概括就是:带有自动变量的匿名函数. 第一次看见Blocks的时候,感觉很类似C语言的函数指针,尤其是Block类型变量,更是有极 ...

  10. findOneAndUpdate的用法详解

    Fragment.findOneAndUpdate({_id:id}, {$set: datas}, {upsert:true, 'new':true}).populate('ads').exec(f ...