首页 > 其他 > 详细

K The Right-angled Triangles

时间:2019-01-06 19:40:16      阅读:132      评论:0      收藏:0      [点我收藏+]

链接:https://ac.nowcoder.com/acm/contest/338/K
来源:牛客网

题目描述

Consider the right-angled triangles with sides of integral length.

Give you the integral length of  the hypotenuse of a right-angled triangle.  Can it construct a right triangle with given hypotenuse c such that the two legs of the triangle are all . integral length?
技术分享图片

输入描述:

There are several test cases. The first line contains an integer T(1≤T≤1,000), T is the number of test cases.

The following T lines contain T test cases, each line contains one test case. For each test case, there is an integer : c, the length of hypotenuse.(1≤c≤45,000).

输出描述:

For each case, output Yes if it can construct a right triangle with given hypotenuse c and sides of integral length , No otherwise.
示例1

输入

复制
4
5
6
15
13

输出

复制
Yes
No
Yes
Yes

优化一下就可以了

简单题
技术分享图片
#include<stdio.h>
#include<math.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        int flag = 0;
        scanf("%d",&n);
        for(int i = 1; i <= 45000&&i!=n; i++)
        {
            double sum = sqrt(n*n - i*i);
            //    printf("%lf ",sum);
            if(sum - (int)sum < 0.000001)
            {


                flag = 1;
                break;
                //printf("YES\n");

            }
        }
//            if(flag==1)
//            break;

        if(flag == 1)
            printf("Yes\n");
        else
            printf("No\n");

    }
}
View Code

 

 

K The Right-angled Triangles

原文:https://www.cnblogs.com/DWVictor/p/10230006.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!