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
    ");
    }
  • 相关阅读:
    dynamic_cast
    struct 字节对齐详解
    CentOS修改系统的默认启动模式为命令号界面
    linux系统备份还原
    linux 缺少libxxx.a 静态链接库
    linux下SVN忽略文件/文件夹的方法
    取消svn add
    centos 中文乱码解决办法2
    安装rpm包时遇到error: Failed dependencies:错误
    Linux rpm 命令参数使用详解[介绍和应用]
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5845038.html
Copyright © 2011-2022 走看看