codeforce 14C

http://vjudge.net/contest/view.action?cid=47975#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 x1y1x2y2 ( - 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

Input
1 1 6 1
1 0 6 0
6 0 6 1
1 1 1 0
Output
YES
Input
0 0 0 3
2 0 0 0
2 2 2 0
0 2 2 2
Output
NO
题目大意:给你四条线段,已知线段的起点和终点的坐标,判断这四条线段是否可以构成一个边平行于坐标轴的矩形。

注意:给定的四条线段不一定可以围成一个四边形。

答题思路:统计出现的八个点的个数,每个点重复两次。在四边形中每一个点和其相邻的两个点的一个横坐标以纵坐标相同。

#include <stdio.h>
struct point
{
    int x,y;
} p[10];
int main()
{
    int i,j,t,f;
    int a[10];
    while(~scanf("%d%d%d%d",&p[0].x,&p[0].y,&p[1].x,&p[1].y))
    {
        int cnt=0;
        f=1;
        if(p[0].x==p[1].x)
                cnt+=1;
            else if(p[0].y==p[1].y)
                cnt+=10;
            else
                f=0;
            a[0]=a[1]=0;
        for(i=2; i<8; i+=2)
        {
            scanf("%d%d%d%d",&p[i].x,&p[i].y,&p[i+1].x,&p[i+1].y);
            if(p[i].x==p[i+1].x)
                cnt+=1;
            else if(p[i].y==p[i+1].y)
                cnt+=10;
            else
                f=0;
            a[i]=a[i+1]=0;
        }
        if(cnt!=22)
            f=0;
        for(i=0; i<8; i++)
        {
            for(j=0; j<8; j++)
            {
                if(p[i].x==p[j].x&&p[i].y==p[j].y)
                    a[i]++;
            }
        }
        for(i=0; i<8; i++)
            if(a[i]!=2)
                f=0;
        if(f)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值