hihocoder 1040 矩形判断解题报告

    用来热身的一道题目,根据题意输入8个点表示4条线,可以利用4个向量来表示这四条线,判断是否组成矩形只需拿出任一条向量判断其余3条向量是否有两条垂直向量,两条平行向量。如果有,则构成矩形,没有则输出"NO"

代码如下。

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int num = 4;
struct Data
{
    int x,y;
};
struct line
{
    Data one,two;
    line(int a = 0,int b = 0,int c = 0,int d = 0)
    {
        one.x = a;one.y = b;
        two.x = c;two.y = d;
    }
}T[num];

void input()
{
    int a,b,c,d;
    for(int i = 0; i < 4; ++i)
    {
        scanf("%d%d%d%d",&a,&b,&c,&d);
        T[i] = *new struct line(a,b,c,d);
    }
}
bool check()
{
    int p = 0,cu = 0;
    int a = T[0].one.x,b = T[0].one.y,c = T[0].two.x,d = T[0].two.y;
    int a2,b2,c2,d2;
    for(int i = 1; i < 4;++i)
    {
        a2 = T[i].one.x;
        b2 = T[i].one.y;
        c2 = T[i].two.x;
        d2 = T[i].two.y;
        int x1 = c - a; int y1 = d - b;
        int x2 = c2 - a2; int y2 = d2 - b2;
        if(x1 * x2 + y1 * y2 == 0)
            cu++;
        if(x2 * y1 - y2 * x1 == 0)
            p++;
    }
    if(cu == 2 && p == 1)
        return true;
    else return false;
}
int main()
{
    int n;cin>>n;
    while(n--)
    {
        input();
        if(check())
            cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值