好贷网好贷款

FZU 1669 Right-angled Triangle 解毕达哥拉斯三元组

发布时间:2016-12-5 0:21:42 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"FZU 1669 Right-angled Triangle 解毕达哥拉斯三元组",主要涉及到FZU 1669 Right-angled Triangle 解毕达哥拉斯三元组方面的内容,对于FZU 1669 Right-angled Triangle 解毕达哥拉斯三元组感兴趣的同学可以参考一下。

点击打开链接 Right-angled Triangle Accept: 52    Submit: 109 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description A triangle is one of the basic shapes of geometry: a polygon with three corners or vertices and three sides or edges which are line segments. A triangle with vertices A, B, and C is denoted △ABC.Triangles can also be classified according to their internal angles, described below using degrees of arc: A right triangle (or right-angled triangle, formerly called a rectangled triangle) has one 90° internal angle (a right angle). The side opposite to the right angle is the hypotenuse; it is the longest side in the right triangle. The other two sides are the legs or catheti (singular: cathetus) of the triangle. Right triangles conform to the Pythagorean Theorem, wherein the sum of the squares of the two legs is equal to the square of the hypotenuse, i.e., a^2 + b^2 = c^2, where a and b are the legs and c is the hypotenuse.An oblique triangle has no internal angle equal to 90°.An obtuse triangle is an oblique triangle with one internal angle larger than 90° (an obtuse angle).An acute triangle is an oblique triangle with internal angles all smaller than 90° (three acute angles). An equilateral triangle is an acute triangle, but not all acute triangles are equilateral triangles. What we consider here is very simple. Give you the length of L, you should calculate there are how many right-angled triangles such that a + b + c ≤ L where a and b are the legs and c is the hypotenuse. You should note that the three numbers a, b and c are all integers.  Input There are multiply test cases. For each test case, the first line is an integer L(12≤L≤2000000), indicating the length of L.  Output For each test case, output the number of right-angled triangles such that a + b + c ≤ L where a and b are the legs and c is the hypotenuse.  Sample Input 1240  Sample Output 15  Hint There are five right-angled triangles where a + b + c ≤ 40. That are one right-angled triangle where a = 3, b = 4 and c = 5; one right-angled triangle where a = 6, b = 8 and c = 10; one right-angled triangle where a = 5, b = 12 and c = 13; one right-angled triangle where a = 9, b = 12 and c = 15; one right-angled triangle where a = 8, b = 15 and c = 17. 求满足以a,b为直角边,c为斜边,且满足a+b+c<=L的直角三角形的个数。 即本原毕达哥拉斯三元组数,枚举m,n,然后求出x,y,z乘以i倍,并且保证在范围内。 //187 ms 208KB #include<stdio.h> #include<math.h> int gcd(int a,int b) { return b==0?a:gcd(b,a%b); } void solve(int t) { int tmp=sqrt(t),x,y,z,ans=0; for(int n=1; n<=tmp; n++) for(int m=n+1; m<=tmp; m++) { if(2*m*m+2*m*n>t)break;//x+y+z>t结束 if(n%2!=m%2) { if(gcd(m,n)==1) { x=m*m-n*n; y=2*m*n; z=m*m+n*n; for(int i=1;; i++) { if(i*(x+y+z)>t)break; ans++; } } } } printf("%d\n",ans); } int main() { int t; while(scanf("%d",&t)!=EOF) solve(t); return 0; }

上一篇:好开心终于有一个自己的博客了 嘻嘻
下一篇:ArcSDE10.2.1 for Oracle 12c的建库模式

相关文章

相关评论