您的位置:首页 > 其它

HDU 5206 Four Inages Strategy

2015-10-03 00:44 405 查看
题意:给出三维空间中的4个点 判断能否组成正方形

比赛时直接套的三维几何的版子 判断3个向量中 是否有两个相等 垂直 且和为第三个向量 

其实可以算出他们两两之间距离 排个序 看小的四个是否相等(4个边) 和剩下两条对角线相等 且长度为根号2倍的边长 (防止误差可以一直用平方来计算)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#define scnaf scanf
#define cahr char
#define bug puts("bugbugbug");
using namespace std;
typedef long long ll;
const int mod=1000000007;
const int maxn=2000+5;
const int inf=1e9;
const int maxe=200000;
struct Point{
ll x,y,z;
Point(ll x=0,ll y=0,ll z=0):x(x),y(y),z(z){ }
}a[10];
Point operator - (Point a,Point b){ return Point(a.x-b.x,a.y-b.y,a.z-b.z); }
Point operator + (Point a,Point b){ return Point(a.x+b.x,a.y+b.y,a.z+b.z); }
Point operator * (Point a,Point b){ return Point(a.x*b.x+a.y*b.y+a.z*b.z); }
bool operator == (const Point &a,const Point &b) {
return a.x==b.x&&a.y==b.y&&a.z==b.z;
}
Point b,c,d;
ll dis(Point a)
{
return a.x*a.x+a.y*a.y+a.z*a.z;
}
int main()
{
int T_T,test=1;
scanf("%d",&T_T);
while(T_T--)
{
int flag=0;
for(int i=0;i<4;i++)
scanf("%I64d%I64d%I64d",&a[i].x,&a[i].y,&a[i].z);
b=a[1]-a[0];
c=a[2]-a[0];
d=a[3]-a[0];
if(dis(b)==dis(c)&&b+c==d&&b*c==0) flag=1;
else if(dis(b)==dis(d)&&b+d==c&&b*d==0) flag=1;
else if(dis(d)==dis(c)&&d+c==b&&d*c==0) flag=1;
printf("Case #%d: ",test++);
if(flag) puts("Yes");
else puts("No");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  几何