• Codeforces Beta Round #14 (Div. 2) C. Four Segments 水题


    C. Four Segments

    题目连接:

    http://codeforces.com/contest/14/problem/C

    Description

    Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him.

    Input

    The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points.

    Output

    Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO».

    Sample Input

    1 1 6 1
    1 0 6 0
    6 0 6 1
    1 1 1 0

    Sample Output

    YES

    Hint

    题意

    给你四条边,问你这四条边能不能恰好组成一个不退化的矩形。

    题解:

    两条线段横着,两条线段竖着,每个端点都被两条直线覆盖就行。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    int f,x1,x2,y1,y2,x,y;
    map<pair<int,int>,int>H;
    int main()
    {
        for(int i=0;i<4;i++)
        {
            scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
            x+=(y1==y2)&&(x1!=x2);
            y+=(x1==x2)&&(y1!=y2);
            H[make_pair(x1,y1)]++;
            H[make_pair(x2,y2)]++;
        }
        f=(x==2)&&(y==2);
        map<pair<int,int>,int>::iterator it;
        for(it=H.begin();it!=H.end();it++)
            if(it->second!=2)
                f=0;
        if(f)printf("YES
    ");
        else printf("NO
    ");
    }
  • 相关阅读:
    STM32寄存器的简介、地址查找,与直接操作寄存器
    SPI初始化寄存器配置
    docker 命令
    SpringBoot接口格式和规范
    算法
    RabbitMQ
    UML概念
    activeMQ和JMS
    设计模式七大原则
    redis缓存
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5845038.html
Copyright © 2020-2023  润新知