At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them with segments of straight lines, then he showed the triangle to Peter. Peter said that Bob's triangle is not right-angled, but is almost right-angled: the triangle itself is not right-angled, but it is possible to move one of the points exactly by distance 1 so, that all the coordinates remain integer, and the triangle become right-angled. Bob asks you to help him and find out if Peter tricks him. By the given coordinates of the triangle you should find out if it is right-angled, almost right-angled, or neither of these.
The first input line contains 6 space-separated integers x1, y1, x2, y2, x3, y3 — coordinates of the triangle's vertices. All the coordinates are integer and don't exceed 100 in absolute value. It's guaranteed that the triangle is nondegenerate, i.e. its total area is not zero.
If the given triangle is right-angled, output RIGHT, if it is almost right-angled, output ALMOST, and if it is neither of these, outputNEITHER.
0 0 2 0 0 1
RIGHT
2 3 4 5 6 6
NEITHER
-1 0 2 0 0 1
ALMOST
给出三个点的坐标,问这三个点是否能构成直角三角形,如果不行,是否能将一个点的位置移动移动一个单位(改变x或y)使得其为直角三角形
使用向量枚举,注意零向量
错了很多次
#include<cstdio>
#include<algorithm>
using namespace std;
struct Point
{
int x,y;
};
void work(Point x[])
{
x[3]=x[0];
for(int i=0;i<3;++i)
{
x[i].x-=x[i+1].x;
x[i].y-=x[i+1].y;
}
x[3]=x[0];
}
bool isRight(Point a,Point b)
{
return a.x*b.x+a.y*b.y==0;
}
bool isZero(Point x[])
{
for(int i=0;i<3;++i)
{
if(x[i].x==x[i].y&&x[i].x==0)
{
return true;
}
}
return false;
}
bool right(Point x[])
{
Point temp[4];
for(int i=0;i<4;++i)
{
temp[i]=x[i];
}
work(temp);
if(isZero(temp))
{
return false;
}
for(int i=0;i<3;++i)
{
if(isRight(temp[i],temp[i+1]))
{
return true;
}
}
return false;
}
bool almost(Point x[])
{
int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};
for(int i=0;i<3;++i)
{
for(int j=0;j<4;++j)
{
Point temp=x[i];
x[i].x+=dx[j];
x[i].y+=dy[j];
if(right(x))
{
return true;
}
x[i]=temp;
}
}
return false;
}
int main()
{
Point x[4]={0};
while(~scanf("%d%d",&x[0].x,&x[0].y))
{
for(int i=1;i<3;++i)
{
scanf("%d%d",&x[i].x,&x[i].y);
}
if(right(x))
{
printf("RIGHT\n");
}
else if(almost(x))
{
printf("ALMOST\n");
}
else
{
printf("NEITHER\n");
}
}
return 0;
}