几何 入门题 UVA 11800 - Determine the Shape

G

Determine the Shape

Input

Standard Input

Output

Standard Output


A toy company recently found that toys like revolver, machine guns, fighting planes are making children violent and destroying the peace of the world. The parents also began to avoid these toys and inclined to educational toys. So they decided to manufacture educational toys. One of these is a electric touch pad on which children can put four points and the program will automatically join the points to form a closed shape. Children will try to guess the shape and when they press a button then it will automatically announce the shape. But they are struggling to determine the shape and seek your help.

Your task is simple. You are given four points, no three of them are collinear, you have to output the simple polygonal shape formed by these points in the following order:

Square
Rectangle
Rhombus
 Parallelogram
Trapezium
Ordinary Quadrilateral

For example if it is possible to form a square with the four points you must output ‘Square’,  if it is not possible to form a square but possible to form a rectangle you must output ‘Rectangle’ and so on.

Input

Input starts with an integer T, the number of test cases (T≤50000). Each test case contains 4 lines. Each of the lines contains two space separated integers xi yi (-10000≤xi, yi≤ 10000) which are the coordinate values of a point.

 

Output

For each set of input output one line in the format “Case k: s”. Here k is the case number starting from 1 and s is the shape as described above. See sample input output for more details.

Sample Input

Sample Output

6

0 0

2 0

2 2

0 2

0 0

3 0

3 2

0 2

0 0

8 4

5 0

3 4

0 0

2 0

3 2

1 2

0 0

5 0

4 3

1 3

0 0

5 0

4 3

1 4

 

Case 1: Square

Case 2: Rectangle

Case 3: Rhombus

Case 4: Parallelogram

Case 5: Trapezium

Case 6: Ordinary Quadrilateral

 

 

Note: If you have forgotten elementary geometry, here is the definitions to remind you:

Square: All sides are of equal size all angles are 90o
Rectangle: Opposite sides are of equal size and all angles are 90o
Rhombus: All sides are of equal size but no angle is 90o
Parallelogram: Opposite sides are of equal size but no angle is 90o
Trapezium: Any two opposite sides are parallel but the other two is not.
Simple Polygon: Polygon having no self intersecting edge. 



题意:给出四个点,确定他是什么形状。


思路:。。。没什么好说的了。


代码:

#include<iostream>
#include<cstdio>
#include<string.h>
#include<math.h>
#include<cstring>
#include<algorithm>
using namespace std;
#define eps 1e-8
struct Point
{
	Point (double xx=0,double yy=0) : x(xx) , y(yy) { }
	double x;
	double y;
};

typedef Point Vector;
Vector operator+(Vector  v1,Vector  v2) { return Vector(v1.x+v2.x,v1.y+v2.y); }
Vector operator-(Vector  v1,Vector  v2) { return Vector(v1.x-v2.x,v1.y-v2.y); }
Vector operator*(Vector  v, double p) { return Vector(v.x*p,v.y*p); }
Vector operator/(Vector  v,double p) { return Vector(v.x/p,v.y/p); }

bool operator < (Point  a,Point  b) { return a.x < b.x || (a.x==b.x && a.y < b.y); }
int dcmp(double x) 
{
	if (fabs(x) < eps) return 0;
	return x < 0 ? -1 : 1; 
}
bool operator==(const Point & a,const Point & b) 
{
	return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0;
}

double Dot(Vector  A,Vector  B) { return A.x*B.x+A.y*B.y; }
double Length(Vector  A) { return sqrt(Dot(A,A)); }
double Angle(Vector A,Vector B) { return acos(Dot(A,B)/Length(A)/Length(B)); }
double Cross(Vector A,Vector B) { return A.x*B.y-A.y*B.x; }
double Area2(Point a,Point b,Point c) {  return Cross(b-a,c-a); }
Vector Rotate(Vector A,double rad) 
{
	return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
Vector Normal(Vector A) { double L = Length(A); return Vector(-A.y/L,A.x/L); }

//点和直线
Point GetLineIntersection(Point P,Vector v,Point Q,Vector w)
{
	Vector u = P-Q;
	double t = Cross(w,u) / Cross(v,w);
	return P+v*t;
}
double DistanceToLine(Point P,Point A,Point B) 
{
	Vector v1 = B-A , v2 = P-A;
	return fabs(Cross(v1,v2))/Length(v1);
}
double DistanceToSegment(Point P,Point A,Point B)
{
	if (A==B) return Length(P-A);
	Vector v1 = B-A , v2 = P-A , v3 = P-B;
	if (dcmp(Dot(v1,v2)) < 0) return Length(v2);
	else if (dcmp(Dot(v1,v3)) > 0) return Length(v3);
	else return fabs(Cross(v1,v2))/Length(v1);
}
Point GetLineProjection(Point P,Point A,Point B) 
{
	Vector v = B-A;
	return A+v*(Dot(v,P-A)/Dot(v,v));
}
bool SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2) 
{
	double c1 = Cross(a2-a1,b1-a1) , c2 = Cross(a2-a1,b2-a1) ,
		     c3 = Cross(b2-b1,a1-b1) , c4 = Cross(b2-b1,a2-b1);
	return dcmp(c1)*dcmp(c2) < 0 && dcmp(c3)*dcmp(c4)<0;
}
bool OnSegment(Point p,Point a,Point b) {
	return dcmp(Cross(a-p,b-p))==0 && dcmp(Dot(a-p,b-p)) < 0;
}
//--------------------------------------------------------------------------------------------

Point p[4];

Vector a , b , c , d;
double lena , lenb , lenc , lend;

void input()
{
	for (int i = 0 ; i < 4 ; ++i) {
		double x , y;
		scanf("%lf%lf",&x,&y);
		p[i] = Point(x,y);
	}
	sort(p,p+4);
	a = p[1]-p[0]; lena = Length(a);
	c = p[2]-p[3]; lenc = Length(c);
	if (SegmentProperIntersection(p[1],p[2],p[0],p[3])) {
		b = p[3]-p[1];
		d = p[2]-p[0];
	}
	else {
		b = p[3]-p[0];
		d = p[2]-p[1];
	}
	lenb = Length(b);
	lend = Length(d);
}

bool isSquare() 
{
	if (dcmp(Dot(a,b))) return false;
	if (dcmp(Dot(b,c))) return false;
	if (dcmp(Dot(c,d))) return false;
	if (dcmp(Dot(d,a))) return false;
	if (dcmp(lena-lenb)) return false;
	return true;
}

bool isRect() 
{
	if (dcmp(Dot(a,b))) return false;
	if (dcmp(Dot(b,c))) return false;
	if (dcmp(Dot(c,d))) return false;
	if (dcmp(Dot(d,a))) return false;
	return true;
}

bool isRhom() 
{
	if (dcmp(lena-lenb)) return false;
	if (dcmp(lena-lenc)) return false;
	if (dcmp(lena-lend)) return false;
	return true;
}

bool isParal() 
{
	double c1 = Cross(a,c) , c2 = Cross(b,d);
	if (dcmp(c1) || dcmp(c2)) return false;
	return true;
}

bool isTrapezium()
{
	double c1 = Cross(a,c) , c2 = Cross(b,d);
	if (dcmp(c1) && dcmp(c2)) return false;
	return true;
}

void solve()
{
	if (isSquare()) printf("Square\n");
	else if (isRect()) printf("Rectangle\n");
	else if (isRhom()) printf("Rhombus\n");
	else if (isParal()) printf("Parallelogram\n");
	else if (isTrapezium()) printf("Trapezium\n");
	else printf("Ordinary Quadrilateral\n");
}

int main()
{
	int T; cin>>T;
	for (int k = 1 ; k <= T ; ++k) {
		input();
		printf("Case %d: ",k);
		solve();
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值