Triangle

There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
Input
The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.

Output
In the first line print either “YES” or “NO” (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.

Example
Input
1 1
Output
NO
Input
5 5
Output
YES
2 1
5 5
-2 4
Input
5 10
Output
YES
-10 4
-2 -2
1 2


题目大意:
给出一个直角三角形的两条边长a、b,看能否将这个三角形放到一个二维平面内,使得三条边都不能平行于坐标轴,如果能输出三个点的坐标,否则输出NO
题解:
两条直角边也就是ab分别是两条不平行于坐标轴的直角三角形的斜边,因为数据不大,那么我们此时就可以暴力做了,看能不能找到这样的两条斜边,如果一个都找不到,那么就是NO,如果能找到就存起来,但是要注意三角形的每个边都不可以平行于坐标轴,特别是找的第三边不能是平行于y轴

#include <stdio.h>
#include <math.h>

int main()
{
    int x,y,z,t,n,m,i,j,a,b,a1,b1,a2,b2;
    int x1[1005],x2[1005],y1[1005],y2[1005];
    int numx,numy;
    scanf("%d%d",&x,&y);
    z = x*x+y*y;
    numx = numy = 0;
    for(i=1;i<x;i++)
    {
        for(j=1;j<x;j++)
        {
            if(i*i+j*j==x*x)
            {
                x1[numx] = i;
                x2[numx] = j;
                numx++;
                if(i!=j)
                {
                    x1[numx] = j;
                    x2[numx] = i;
                    numx++; 
                }
            }
            if(i*i+j*j>x*x)
            {
                break;
            }
        }
    }
    for(i=1;i<y;i++)
    {
        for(j=1;j<y;j++)
        {
            if(i*i+j*j==y*y)
            {
                y1[numy] = i;
                y2[numy] = j;
                numy++;
                if(i!=j)
                {
                    y1[numy] = j;
                    y2[numy] = i;
                    numy++;
                }
            }
            if(i*i+j*j>y*y)
            {
                break;
            }
        }
    }
    if(numx==0||numy==0)
    {
        printf("NO\n");
    }
    else
    {
        for(i=0;i<numx;i++)
        {
            a1 = x1[i];
            b1 = x2[i]; 
            t = 0; 
            for(j=0;j<numy;j++)
            {
                a2 = y1[j];
                b2 = y2[j];
                if(b1!=b2)
                {
                    int tem = (a1+a2)*(a1+a2)+(b1-b2)*(b1-b2);
                    if(tem==z)
                    {
                        t = 1;
                        break;
                    }
                } 
            }
            if(t)
            {
                break;
            }   
        }
        if(t)
        {
            printf("YES\n");
            printf("0 0\n"); 
            printf("%d %d\n",-a1,b1);
            printf("%d %d\n",a2,b2);
        }
        else
        {
            printf("NO\n");
        }   
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值