CF18A 幾何

life4711發表於2015-01-04

http://codeforces.com/problemset/problem/18/A

A. Triangle
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

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.

Input

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.

Output

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.

Sample test(s)
input
0 0 2 0 0 1
output
RIGHT
input
2 3 4 5 6 6
output
NEITHER
input
-1 0 2 0 0 1
output
ALMOST

/**
CF18A 計算幾何
題目大意:給出三個點,保證能構成三角形,判斷是否是直角三角形,如果不是對於三個點中隨意移動一個點的座標1,是否能構成直角三角形
解題思路:利用向量。有一個坑,點的座標平移後不能保證還能構成三角形,因此要特別判斷
*/
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;

int x1,x2,x3,y1,y2,y3;

bool ok(int x1,int y1,int x2,int y2,int x3,int y3)
{
    int a=x2-x1,a1=y2-y1,b=x3-x1,b1=y3-y1;
    int x=x1-x2,xx=y1-y2,y=x3-x2,yy=y3-y2;
    int p=x1-x3,pp=y1-y3,q=x2-x3,qq=y2-y3;
    if(a*b1==b*a1)return 0;///判斷是否能構成三角形
    if(a*b+b1*a1==0||x*y+yy*xx==0||p*q+qq*pp==0)
        return 1;
    return 0;
}

int main()
{
    while(~scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3))
    {
        if(ok(x1,y1,x2,y2,x3,y3))
            printf("RIGHT\n");
        else if(ok(x1+1,y1,x2,y2,x3,y3)||ok(x1,y1+1,x2,y2,x3,y3)||ok(x1,y1,x2+1,y2,x3,y3)||ok(x1,y1,x2,y2+1,x3,y3)||ok(x1,y1,x2,y2,x3+1,y3)||ok(x1,y1,x2,y2,x3,y3+1)||
                ok(x1-1,y1,x2,y2,x3,y3)||ok(x1,y1-1,x2,y2,x3,y3)||ok(x1,y1,x2-1,y2,x3,y3)||ok(x1,y1,x2,y2-1,x3,y3)||ok(x1,y1,x2,y2,x3-1,y3)||ok(x1,y1,x2,y2,x3,y3-1))
            printf("ALMOST\n");
        else
            printf("NEITHER\n");
    }
    return 0;
}