uva 11800 - Determine the Shape

942 篇文章 2 订阅
99 篇文章 0 订阅

题目链接:uva 11800 - Determine the Shape

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;
const int maxn = 4;
const double eps = 1e-6;
const char T[6][30] = {"Square", "Rectangle", "Rhombus", "Parallelogram", "Trapezium", "Ordinary Quadrilateral"};

struct Point {
	double x, y;
	void input() { scanf("%lf%lf", &x, &y); }
	friend bool operator < (const Point& a, const Point& b) {
		if (a.x != b.x)
			return a.x < b.x;
		return a.y < b.y;
	}
}p[maxn];

struct Line {
	double A, B, C;
};

inline double distant(Point a, Point b) {
	double x = a.x - b.x;
	double y = a.y - b.y;
	return sqrt(x * x + y * y);
}

Line getLine (Point a, Point b) {
	double A = b.y - a.y;
	double B = a.x - b.x;
	double C = a.y * b.x - a.x * b.y;
	return (Line){A, B, C};
}

bool parallel(Line a, Line b) {
	double A = a.A * b.B;
	double B = a.B * b.A;
	return fabs(A - B) < eps;
}

bool vertical(Line a, Line b) {
	double A = a.A * b.A;
	double B = a.B * b.B;
	return fabs(A + B) < eps;
}


int solve () {
	bool a = parallel(getLine(p[0], p[1]), getLine(p[2], p[3]));
	bool b = parallel(getLine(p[0], p[3]), getLine(p[1], p[2]));

	if (a && b) {
		bool flag = vertical(getLine(p[0], p[1]), getLine(p[1], p[2]));
		double c = distant(p[0], p[1]);
		double d = distant(p[0], p[3]);
		if (fabs(c - d) < eps)
			return flag ? 0 : 2;
		else
			return flag ? 1 : 3;

	} else if (a || b)
		return 4;
	return 5;
}

int main () {
	int cas;
	scanf("%d", &cas);
	for (int kcas = 1; kcas <= cas; kcas++) {
		for (int i = 0; i < maxn; i++)
			p[i].input();
		int ans = 5;
		do {
			ans = min(ans, solve());
		} while (next_permutation(p, p + maxn));
		printf("Case %d: %s\n", kcas, T[ans]);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值