给你两个数 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;
}