Codeforces 407 A. Triangle 【Codeforces Round #239 (Div. 1)】

点击打开链接

A. Triangle
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Sample test(s)
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 ,分别是一个直角三角形的两条直角边,让你求出是否存在不与坐标轴平行的三角形的三个坐标。。。

如果存在输出 YES,并且将这三个坐标输出,(任选一个输出),否则输出NO


解题思路:


首先想到的是这两条直角边一定是其他直角三角形的一条斜边。。。然后数据范围并不是很大,所以就直接枚举就行了。

有一个点的坐标是固定的 就是原点 (0, 0)点。。。

上代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;

#define MM(a) memset(a,0,sizeof(a))

typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 3e3+5;
const int mod = 1e9+7;
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
LL gcd(LL a, LL b)
{
    if(b == 0)
        return a;
    return gcd(b, a%b);
}
struct node
{
    int x, y;
};
node p1[maxn], p2[maxn];
int main()
{
    int a, b;
    while(cin>>a>>b)
    {
        int cnt1, cnt2, cnt, j;
        double tmp;
        cnt1 = cnt2 = cnt = 0;
        for(int i=1; i<a; i++)
        {
            tmp = a*a-i*i;
            j = (int)sqrt(tmp);
            if(i*i+j*j == a*a)
            {
                p1[cnt1].x = i;
                p1[cnt1++].y = j;
            }
        }
        for(int i=1; i<b; i++)
        {
            tmp = b*b-i*i;
            j = (int)sqrt(tmp);
            if(i*i+j*j == b*b)
            {
                p2[cnt2].x = i;
                p2[cnt2++].y = j;
            }
        }
        bool ok = false;
        for(int i=0; i<cnt1; i++)
        {
            for(int j=0; j<cnt2; j++)
            {
                if(p1[i].y!=p2[j].y && p1[i].x*p2[j].x==p1[i].y*p2[j].y)
                {
                    puts("YES");
                    puts("0 0");
                    printf("%d %d\n",-p1[i].x,p1[i].y);
                    printf("%d %d\n",p2[j].x,p2[j].y);
                    ok = true;
                    break;
                }
            }
            if(ok)
                break;
        }
        if(!ok)
            puts("NO");
    }
    return 0;
}

 	


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值