UVa 11800 - Determine the Shape

思路一定要清晰 , 题意很简单 , 但是如果一个个的讨论肯定是繁琐的 , 还记得初中课本上怎么定义这些四边形的么 , 按照顺序一个个的来




注意: 四个点的顺序是任意的 , 所以需要极角排序 , 你可以使用叉乘+象限排序的方式  , 但是博主偷懒使用了atan2 , 可能会有精度问题但只有4个点是吧


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <algorithm>

using namespace std;
double eps = 1e-10;

int dcmp(double a , double b) { return (fabs(a-b)<=eps)?0:(a<b?-1:1); }

struct points 
{
	int x , y;
	points(int x = 0, int y = 0):x(x),y(y){}
}p[4];

typedef points Vector ;

Vector  operator +(points a , points b) { return Vector(a.x+b.x , a.y+b.y); }
Vector  operator -(points a , points b) { return Vector(a.x-b.x , a.y-b.y); }
Vector  operator /(points a , int    b) { return Vector(a.x/b   , a.y/b  ); }
int Dot(Vector a , Vector b) { return a.x*b.x+a.y*b.y; }

Vector orig;

int p2(int a) { return a*a; }

bool cmp(points& a , points& b)
{
	double t1 = atan2(1.0*a.x-orig.x, 1.0*a.y-orig.y);
	double t2 = atan2(1.0*b.x-orig.x, 1.0*b.y-orig.y);
	return t1<t2; 
}

bool parell(Vector a , Vector b)
{
	return a.x*b.y == a.y*b.x; 
}

void solve()
{
	orig = (p[0]+p[1])/2; 
	sort(p , p+4 , cmp);
	if(parell(p[0]-p[1], p[2]-p[3]) || parell(p[0]-p[3], p[1]-p[2]))
	{
		if(parell(p[0]-p[1], p[2]-p[3]) && parell(p[0]-p[3], p[1]-p[2]))
		{
			bool eq = ( p2(p[0].x-p[1].x)+p2(p[0].y-p[1].y) == p2(p[1].x-p[2].x)+p2(p[1].y-p[2].y) );
			bool re = (Dot(p[0]-p[1], p[0]-p[3])==0) ;
			
			if(eq && re) { cout<<"Square\n"; return; }
			else if(eq ) { cout<<"Rhombus\n"; return;}
			else if(re ) { cout<<"Rectangle\n"; return; }
			else { cout<<"Parallelogram\n";     return; }
		}
		else { cout<<"Trapezium\n"; return ; }
	}
	else { cout<<"Ordinary Quadrilateral\n"; return ; }
}

int main(int argc, char *argv[]) {
	
	int t;
	scanf("%d",&t);
	
	for(int Case=1;Case<=t;Case++)
	{
		for(int i=0;i<4;i++) scanf("%d%d",&p[i].x,&p[i].y);
		cout<<"Case "<<Case<<": ";
		solve();	
	}
	
	return 0;
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值