• hihocoder 1040(矩形判断)


    题目链接:传送门

    题目大意:给你四条线段,判断能否围成一个面积大于0的矩形,能输出YES,不能输出NO

    题目思路:

           合法的四条线段应该满足

         1.应该必须有四个不同的点 

         2.线段斜率分为两组,组内相同组间不同 

         3.若有斜率为0或斜率不存在的线段需特判,否则看斜率不同的线段乘积==-1?"YES":"NO"

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <cstring>
    #include <stack>
    #include <cctype>
    #include <queue>
    #include <string>
    #include <vector>
    #include <set>
    #include <map>
    #include <climits>
    #define lson root<<1,l,mid
    #define rson root<<1|1,mid+1,r
    #define fi first
    #define se second
    #define ping(x,y) ((x-y)*(x-y))
    #define mst(x,y) memset(x,y,sizeof(x))
    #define mcp(x,y) memcpy(x,y,sizeof(y))
    using namespace std;
    #define gamma 0.5772156649015328606065120
    #define MOD 1000000007
    #define inf 0x3f3f3f3f
    #define N 200005
    #define maxn 1050
    typedef pair<int,int> PII;
    typedef long long LL;
    
    int n,m;
    struct Node{
        int x,y;
        bool operator<(const Node&a)const{
            if(x==a.x)
            return y<a.y;
            return x<a.x;
        }
    }node[4][2];
    map<PII,int>M; ///判断顶点数
    double k[5];///斜率
    
    int main(){
        int i,j,group,x,y,v;
        while(scanf("%d",&group)!=EOF){
            while(group--){
                M.clear();
                for(i=0;i<=3;++i){
                    scanf("%d%d",&node[i][0].x,&node[i][0].y);
                    scanf("%d%d",&node[i][1].x,&node[i][1].y);
                    sort(node[i],node[i]+2);
                }
                int num=0;
                for(i=0;i<=3;++i)for(j=0;j<=1;++j){
                    PII p=make_pair(node[i][j].x,node[i][j].y);
                    if(!M[p]) ++num;
                    M[p]=1;
                }
                if(num!=4){printf("NO
    ");continue;}///顶点数不为4,NO
                for(i=0;i<4;++i){
                    if(node[i][0].x==node[i][1].x){ ///斜率不存在
                        k[i]=inf;
                        continue;
                    }
                    else if(node[i][0].y==node[i][1].y){ 
                        k[i]=0;
                        continue;
                    }
                    else{
                        k[i]=(double)(node[i][1].y-node[i][0].y)/(double)(node[i][1].x-node[i][0].x);
                    }
                }
                sort(k,k+4);
                if(fabs(k[0]-k[1])<1e-5&&fabs(k[2]-k[3])<1e-5){
                    if(fabs(k[1]-k[2])<1e-5)printf("NO
    ");
                    else{
                        if(fabs(k[1]*k[2]+1)<1e-5)printf("YES
    ");
                        else if(fabs(k[0])<1e-5&&fabs(k[3]-inf)<1e-5)printf("YES
    ");
                        else printf("NO
    ");
                    }
                }
                else printf("NO
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    jQuery点击弹出遮罩层(弹出模态框),点击模态框消失
    ubuntu delect opencv
    protobuf安装
    caffe中使用matlab接口
    protobuf安装
    caffe安装2
    caffe安装1
    PHP学习笔记,js
    PHP学习笔记-动态属性添加
    Ubuntu14.04安装Moodle
  • 原文地址:https://www.cnblogs.com/Kurokey/p/5656574.html
Copyright © 2020-2023  润新知