[HihoCoder]#1040 : 矩形判断

华电北风吹
天津大学认知计算与应用重点实验室
2016-06-24

题目链接:
http://hihocoder.com/problemset/problem/1040

题目分析:

// problem1040.cpp : 定义控制台应用程序的入口点。
// #1040 : 矩形判断
// http://hihocoder.com/problemset/problem/1040
// 张正义 2016-04-14

#include "stdafx.h"

#include 
using namespace std;

int data[4][4];

bool CheckPoint()
{
    for (int i = 0; i < 4; i++)
    {
        if ((data[i][0] == data[i][2]) && ((data[i][1] == data[i][3])))
            return true;
    }
    return false;
}

bool func()
{
    int start = 0, big = 0;
    for (int i = 0; i < 4; i++)
    {
        int j;
        for (j = 0; j < 4; j++)
        {
            if (j == start)
                continue;
            if (big == 0)
            {
                if ((data[start][2] == data[j][0]) && (data[start][3] == data[j][1]))
                {
                    big = 0;
                    break;
                }
                if ((data[start][2] == data[j][2]) && (data[start][3] == data[j][3]))
                {
                    big = 1;
                    break;
                }
            }
            else
            {
                if ((data[start][0] == data[j][0]) && (data[start][1] == data[j][1]))
                {
                    big = 0;
                    break;
                }
                if ((data[start][0] == data[j][2]) && (data[start][1] == data[j][3]))
                {
                    big = 1;
                    break;
                }
            }
        }
        if (j == 4)
            return false;
        if ((data[start][2] - data[start][0])*(data[j][2] - data[j][0]) + (data[start][3] - data[start][1])*(data[j][3] - data[j][1])==0)
        {
            start = j;
        }
        else
        {
            return false;
        }
    }
    return true;
}

int main()
{
    int T;
    cin >> T;
    for (int caseNum = 0; caseNum < T; caseNum++)
    {
        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                cin >> data[i][j];
            }
        }
        if (CheckPoint())
        {
            cout << "NO" << endl;
            continue;
        }
        if (func())
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    system("pause");
    return 0;
}

解题报告:

你可能感兴趣的:(#,HihoCoder)