zoukankan      html  css  js  c++  java
  • 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
    ");
    }
  • 相关阅读:
    jquery模拟刮刮乐
    jq默认选中每项第一个
    让一个div水平且垂直居中
    ES6模块的import和export用法总结
    linux 标准目录
    spring 注解配置
    多线程下的两种单例写法
    java版二叉树算法实现
    JAVA版A星算法实现
    对于宫格地图寻最短路径的一个广度搜索算法
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5845038.html
Copyright © 2011-2022 走看看