CodeForces - 18A判断直角三角形

给你三个坐标,都是整数,如果已经构成直角三角形,那么输出RIGHT,如果某个点可以刚好移动一个单位,构成直角三角形,那么输出ALMOST,否则输出NEITHER.

刚开始对第二种判定没思路,然后一想,这三个点的坐标都是整数,而且能且必须只移动一个单位,那么,只能沿着坐标轴的方向移动,也就是只能是x+1x-1y+1y-1四种情况。枚举判断即可。
另外,注意两点重合的情况,wa了好多发。

AC代码:

/*
 * @Author: hesorchen
 * @LastEditTime: 2020-04-20 23:23:08
 * @1  : ┌───┐   ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┐
 * @2  : │Esc│   │ F1│ F2│ F3│ F4│ │ F5│ F6│ F7│ F8│ │ F9│F10│F11│F12│ │P/S│S/L│P/B│  ┌┐    ┌┐    ┌┐
 * @3  : └───┘   └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┘  └┘    └┘    └┘
 * @4  : ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐ ┌───┬───┬───┐ ┌───┬───┬───┬───┐
 * @5  : │~ `│! 1│@ 2│# 3│$ 4│% 5│^ 6│& 7│* 8│( 9│) 0│_ -│+ =│ BacSp │ │Ins│Hom│PUp│ │N L│ / │ * │ - │
 * @6  : ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─────┤ ├───┼───┼───┤ ├───┼───┼───┼───┤
 * @7  : │ Tab │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │{ [│} ]│ | \ │ │Del│End│PDn│ │ 7 │ 8 │ 9 │   │
 * @8  : ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤ └───┴───┴───┘ ├───┼───┼───┤ + │
 * @9  : │ Caps │ A │ S │ D │ F │ G │ H │ J │ K │ L │: ;│" '│ Enter  │               │ 4 │ 5 │ 6 │   │
 * @10 : ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────────┤     ┌───┐     ├───┼───┼───┼───┤
 * @11 : │ Shift  │ Z │ X │ C │ V │ B │ N │ M │< ,│> .│? /│  Shift   │     │ ↑ │     │ 1 │ 2 │ 3 │   │
 * @12 : ├─────┬──┴─┬─┴──┬┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬────┬────┤ ┌───┼───┼───┐ ├───┴───┼───┤ E││
 * @13 : │ Ctrl│    │Alt │         Space         │ Alt│    │    │Ctrl│ │ ← │ ↓ │ → │ │   0   │ . │←─┘│
 * @14 : └─────┴────┴────┴───────────────────────┴────┴────┴────┴────┘ └───┴───┴───┘ └───────┴───┴───┘
 */

#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define endl '\n'
#define PI cos(-1)
#define ll long long
#define INF 0x3f3f3f3f
#define mod 1000000009
#define lowbit(abcd) (abcd & (-abcd))

int p[10];
int a[5];
inline int len(int x1, int y1, int x2, int y2)
{
    return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
bool check(int x1, int y1, int x2, int y2, int x3, int y3)
{
    if ((x1 == x2 && y1 == y2) || (x1 == x3 && y1 == y3) || (x2 == x3 && y2 == y3))
        return 0;
    a[1] = len(x1, y1, x2, y2), a[2] = len(x2, y2, x3, y3), a[3] = len(x3, y3, x1, y1);
    sort(a + 1, a + 4);
    if (a[2] + a[1] == a[3])
        return 1;
    return 0;
}
int main()
{
    for (int i = 1; i <= 6; i++)
        cin >> p[i];
    if (check(p[1], p[2], p[3], p[4], p[5], p[6]))
        printf("RIGHT\n");
    else
    {
        int ff = 0;
        if (check(p[1] + 1, p[2], p[3], p[4], p[5], p[6]))
            ff = 1;
        if (check(p[1], p[2] + 1, p[3], p[4], p[5], p[6]))
            ff = 1;
        if (check(p[1], p[2], p[3] + 1, p[4], p[5], p[6]))
            ff = 1;
        if (check(p[1], p[2], p[3], p[4] + 1, p[5], p[6]))
            ff = 1;
        if (check(p[1], p[2], p[3], p[4], p[5] + 1, p[6]))
            ff = 1;
        if (check(p[1], p[2], p[3], p[4], p[5], p[6] + 1))
            ff = 1;

        if (check(p[1] - 1, p[2], p[3], p[4], p[5], p[6]))
            ff = 1;
        if (check(p[1], p[2] - 1, p[3], p[4], p[5], p[6]))
            ff = 1;
        if (check(p[1], p[2], p[3] - 1, p[4], p[5], p[6]))
            ff = 1;
        if (check(p[1], p[2], p[3], p[4] - 1, p[5], p[6]))
            ff = 1;
        if (check(p[1], p[2], p[3], p[4], p[5] - 1, p[6]))
            ff = 1;
        if (check(p[1], p[2], p[3], p[4], p[5], p[6] - 1))
            ff = 1;
        if (ff)
            printf("ALMOST\n");
        else
            printf("NEITHER\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hesorchen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值