(Problem 39)Integer right triangles
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的更多相关文章
- 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 ...
- Project Euler 39 Integer right triangles( 素勾股数 )
题意:若三边长 { a , b , c } 均为整数的直角三角形周长为 p ,当 p = 120 时,恰好存在三个不同的解:{ 20 , 48 , 52 } , { 24 , 45 , 51 } , ...
- Problem D: Integer Inquiry
Problem D: Integer InquiryTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 41 Solved: 12[Submit][Status ...
- 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 ...
- 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 且为互质的奇数 ...
- EularProject 39:给周长推断构成直角三角形个数
华电北风吹 天津大学认知计算与应用重点实验室 完毕日期:2015/7/30 Integer right triangles Problem 39 If p is the perimeter of a ...
- Leetcode 题目整理-3 Palindrome Number & Roman to Integer
9. Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. clic ...
- 65. Reverse Integer && Palindrome Number
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, re ...
- SGU 248. Integer Linear Programming( 背包dp )
看了半天...发现就是个背包...然后就不打算敲了. 看了一眼forum..顿时吓傻..其他人用了gcd啊什么的各种奇怪的东西..然后还是敲了个背包结果就AC了= =既然写了代码就扔上来吧... -- ...
随机推荐
- 安装rac遇到的问题总结:
1. 选择虚拟机工具 这个过程是非常的波折.这次安装也让我吸取了很大教训,获得了宝贵经验. 首先啊,必须了解rac的机制. 共享磁盘+多实例. 这就意味着,我们必须使用一个支持共享磁盘的虚拟机. 第一 ...
- ios文本常见属性
文本属性Attributes 1.NSKernAttributeName: @10 调整字距 kerning 字距调整 2.NSFontAttributeName : [UIFont systemFo ...
- Csharp多态的实现(抽象类)
1.什么是抽象类 抽象类是虚拟的类,不能创建对象,用abstract修饰,在子类中用override进行重写 抽象类中可以存放抽象方法,属性,也可以存放非抽象方法,属性(这个在下面的代码可以看出来的) ...
- BOOST_PP_INC_I(x)实现
这个比较有意思,# define BOOST_PP_INC_I(x) BOOST_PP_INC_ ## x 连接在一起以后,然后定义为x+1 实现了inc功能,不过最多也就到255 # /* Copy ...
- PHP 提交checkbox表单时 判断复选框是否被选中
function GetTitleImgPath(){ $titleImgPath = ""; if (isset($_POST["titlecheckbox" ...
- QF——iOS沙盒机制
iOS沙盒机制: 什么是沙盒机制? 点击进入 点击进入 沙盒机制(SandBox)是一种安全体系,它规定了APP的所有文件数据都必须存储在这片区域.所有非代码文件的数据都保存在这片区域. 沙盒里有 ...
- QF——OC内存管理详解
堆的内存管理: 我们所说的内存管理,其实就是堆的内存管理.因为栈的内存会自动回收,堆的内存需要我们手动回收. 栈中一般存储的是基本数据类型变量和指向对象的指针(对象的引用),而真实的对象存储在堆中.因 ...
- 关于ThreadAbortExcption异常处理
之前程序中,使用Thread.Abort()方法来终止线程的运行,但它是抛出ThreadAbortException异常来终止线程. 异常信息摘要: Unhandled Exception:Threa ...
- Application Loader下载安装和上传IOS app程序
如果您安装了最新版的XCode开发环境.对于在4.2及以上版本,Developer/Applications/Utilities目录中已经有ApplicationLoader程序,无需执行以下单独安装 ...
- linux文件名乱码解决办法
1.linux解压压缩文件乱码 unzip -O CP936 xxx.zip 2.一般文件用convmv sudo convmv -f gbk -t utf-8 -r --notest /your_d ...