codeforce 18A

http://vjudge.net/contest/view.action?cid=48098#problem/A

Description

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 Input

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
题意:给你三个点的坐标,这三个点一定可以组成三角形。如果能够成直角三角形就输出RIGHT,如果不能构成直角三角形而将三个点的坐标的一个任意改变1(保证改变后三点坐标仍然是整数)若可以组成直角三角形就输出ALMODST,以上两种情况都不满足就输出NEITHET。

解题思路:判断是否可以构成直角三角形可以运用勾股定理,也可以用向量来判角是否为直角。一定要注意的是,题目虽然保证给出的三个点可以构成三角形但是你任意移动坐标1后就不一定了给组数据(0,0)(1,0)(4,1)答案:NEITHET

我的代码(向量判直角)

#include <stdio.h>
#include <iostream>
using namespace std;
int angle(int x1,int y1,int x2,int y2,int x3,int y3)
{
    int x,y,z;
    if(((x1==x2)&&(y1==y2))||((x1==x3)&&(y1==y3))||((x2==x3)&&(y2==y3)))
        return 0;
    x=(x2-x1)*(x3-x1)+(y2-y1)*(y3-y1);
    y=(x1-x2)*(x3-x2)+(y1-y2)*(y3-y2);
    z=(x1-x3)*(x2-x3)+(y1-y3)*(y2-y3);
    //printf("%d,%d,%d\n",x,y,z);
    if(x==0||y==0||z==0)
        return 1;
    return 0;
}
int main()
{
    int x1,y1,x2,y2,x3,y3;
    while(~scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3))
    {
        if(angle(x1,y1,x2,y2,x3,y3))
        {
            printf("RIGHT\n");
            continue;
        }
        if(angle(x1-1,y1,x2,y2,x3,y3)==1||angle(x1+1,y1,x2,y2,x3,y3)==1||angle(x1,y1+1,x2,y2,x3,y3)==1||angle(x1,y1-1,x2,y2,x3,y3)==1||angle(x1,y1,x2+1,y2,x3,y3)==1||angle(x1,y1,x2-1,y2,x3,y3)==1||angle(x1,y1,x2,y2+1,x3,y3)==1||angle(x1,y1,x2,y2-1,x3,y3)==1||angle(x1,y1,x2,y2,x3+1,y3)==1||angle(x1,y1,x2,y2,x3-1,y3)==1||angle(x1,y1,x2,y2,x3,y3+1)==1||angle(x1,y1,x2,y2,x3,y3-1)==1)
        {
            printf("ALMOST\n");
            continue;
        }
        printf("NEITHER\n");
    }
    return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值