数论:zoj 2540 Form a Square

本文提供了一种通过计算四点坐标的距离来判断这些点是否可以构成矩形的方法。利用点之间的距离关系,该算法能够确定四个点是否满足矩形的几何特性:对边相等且四个角为直角。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【转】http://blog.youkuaiyun.com/zxy_snow/article/details/6153629

 

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
using namespace std;
typedef struct{
	double x,y;
}coor;
coor c[4];
double len(double x,double y,double xx,double yy)
{
	return (x-xx)*(x-xx)+(y-yy)*(y-yy);
}
int compute(coor a,coor b,coor c,coor d)
{
	if( len(a.x,a.y,c.x,c.y) == len(a.x,a.y,b.x,b.y) + len(b.x,b.y,c.x,c.y) )
		if( len(b.x,b.y,c.x,c.y) + len(c.x,c.y,d.x,d.y) == len(b.x,b.y,d.x,d.y) )
			if( len(a.x,a.y,b.x,b.y) == len(b.x,b.y,c.x,c.y) )
				return 1;
	return 0;
}
int main()
{
	int ncases,ind = 1,blank = 0,i,j,k,x,flag;
	scanf("%d",&ncases);
	while( ncases-- )
	{
		flag = 0;
		if( blank ) printf("/n");
		blank = 1;
		for(i=0; i<4; i++)
			scanf("%lf %lf",&c[i].x,&c[i].y);
		for(i=0; i<4; i++)
			for(j=0; j<4; j++)
			{
				if( j == i ) continue;
				for(k=0; k<4; k++)
				{
					if( k == i || k == j ) continue;
					x = 6 - k - i - j;
					if( compute(c[i],c[j],c[k],c[x]) == 1 )
					{
						flag = 1;
						goto end;
					}
				}
			}
		end:;
		printf("Case %d:/n",ind++);
		if( flag ) 
			printf("Yes/n");
		else 
			printf("No/n");
	}
return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值