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. log4j异常问题

    log4j:WARN No appenders could be found for logger   转自:最爱NBA 直接写我的解决办法:在src下面新建file名为log4j.propertie ...

  2. windows下,用绝对路径向html文件中插入图片

    首先注意路径中是否包含中文名比如 <img src="F:\头像\小黄人.jpg" width="500" height="200"/ ...

  3. 转:script中的async和defer

    script中的async和defer defer: This Boolean attribute is set to indicate to a browser that the script is ...

  4. 优盘(U 盘) 采用TLC, MLC, SLC芯片 的区别 与使用寿命

    最近一直在看大家在讨论sandisk,pny,金士顿等大厂都开始用tlc的芯片问题,让大家基本都不敢用U盘存数据了按照之前的擦写参数TLC        1000次MLC       10000次SL ...

  5. Delphi OleVariant 类型的用法

    因客户需求,对客户的指纹机与公司产品进行集成,需要对指纹机做接口的二次开发,郁闷的是产商只提供了VB和C的DEMO示例,没有Delphi的,公司没有VB,C的环境,不能打开这二种语言的示例,因为本公司 ...

  6. 用sqlserver处理excel表格

    本来最近在研究微信公众平台的,老大临时交我个任务,把excel表格里的数据导入sql数据库,我想这so easy嘛. 没想都在上面消磨了两天... 把情况介绍下:在数据库中有如下这样结构的表(A表) ...

  7. 通过iframe在其父窗口中打开隐藏元素

    先上代码 $(".login-box,#dl,.top_01 a:eq(1)").click(function(){ if(self!=top){ parent.$("# ...

  8. 《4》CentOS7.0+OpenStack+kvm云平台部署—配置Nova

    感谢朋友支持本博客,欢迎共同探讨交流,因为能力和时间有限,错误之处在所难免,欢迎指正! 假设转载.请保留作者信息. 博客地址:http://blog.csdn.net/qq_21398167 原博文地 ...

  9. CouchDB简单应用

    CouchDB是众多称作NoSQL解决方案中的一员.与众不同的是,CouchDB是一个面向文档的数据库,在它里面所有文档域(Field)都是以键值对的形式存储的.域(Field)可以是一个简单的键值对 ...

  10. ES6 JavaScript Promise的感性认知

    http://www.zhangxinxu.com/wordpress/2014/02/es6-javascript-promise-感性认知/ 这篇文章讲的很透彻 http://www.zhangx ...