A. Triangle

来源:互联网 发布:淘宝联盟如何推广赚钱 编辑:程序博客网 时间:2024/05/24 11:13
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
v退化三角形和三角形的判断
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#include <stack>
#define maxn 10000+5
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;

using namespace std;

bool cmp(int a,int b){
return a>b;
}
pair
<int,int >p[4];
int dir[4][2]={1,0,0,1,0,-1,-1,0};
int line(int a,int b,int c,int d){
return (a-c)*(a-c)+(d-b)*(d-b);
}
int arr[3];
int judge(int x1,int y1,int x2,int y2,int x3,int y3){
if(x1==x2&&y1==y2)return 0;
if(x2==x3&&y2==y3)return 0;
if(x1==x3&&y1==y3)return 0;
arr
[0]=line(x1,y1,x2,y2);
arr
[1]=line(x1,y1,x3,y3);
arr
[2]=line(x2,y2,x3,y3);
sort
(arr,arr+3);
if(arr[2]==arr[1]+arr[0])
return 1;
return 0;
}

int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int x1,y1,x2,y2,x3,y3;
while(cin>>p[1].first>>p[1].second>>p[2].first>>p[2].second>>p[3].first>>p[3].second){
if(judge(p[1].first,p[1].second,p[2].first,p[2].second,p[3].first,p[3].second)){
cout
<<"RIGHT";return 0;
}
else{
for(int i=0;i<4;i++){
int nx=p[1].first+dir[i][0];
int ny=p[1].second+dir[i][1];
if(judge(nx,ny,p[2].first,p[2].second,p[3].first,p[3].second)){
cout
<<"ALMOST";return 0;
}
}
for(int i=0;i<4;i++){

int nx=p[2].first+dir[i][0];
int ny=p[2].second+dir[i][1];
if(judge(p[1].first,p[1].second,nx,ny,p[3].first,p[3].second)){

cout
<<"ALMOST";return 0;
}
}
for(int i=0;i<4;i++){

int nx=p[3].first+dir[i][0];
int ny=p[3].second+dir[i][1];
if(judge(p[1].first,p[1].second,p[2].first,p[2].second,nx,ny)){
cout
<<"ALMOST";return 0;
}
}
}
cout
<<"NEITHER";
}
return0;
}

0 0
原创粉丝点击