枚举两个点当做0号点的相邻两边,判断两边长度是否相等和垂直,然后用向量推最后一个点,比较是否相等
2 0 0 0 0 1 0 1 0 0 1 1 0 1 1 1 2 2 2 3 3 3 4 4 4
Case #1: Yes Case #2: No
/* ***********************************************
Author :CKboss
Created Time :2015年04月19日 星期日 08时52分45秒
File Name :A.cpp
************************************************ */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long int LL;
struct Point
{
LL x,y,z;
void input() { cin>>x>>y>>z; }
LL len() { return x*x+y*y+z*z; }
}p[4];
bool check(int a,int b,int c)
{
Point pp1 = (Point){p[a].x-p[0].x,p[a].y-p[0].y,p[a].z-p[0].z};
Point pp2 = (Point){p[b].x-p[0].x,p[b].y-p[0].y,p[b].z-p[0].z};
Point pp3 = (Point){pp1.x-pp2.x,pp1.y-pp2.y,pp1.z-pp2.z};
LL Len1=pp1.len();
LL Len2=pp2.len();
LL Len3=pp3.len();
if(Len1!=Len2) return false;
if(Len1+Len2!=Len3) return false;
LL dx=p[a].x+p[b].x-p[0].x;
LL dy=p[a].y+p[b].y-p[0].y;
LL dz=p[a].z+p[b].z-p[0].z;
if(dx==p[c].x&&dy==p[c].y&&dz==p[c].z) return true;
return false;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T_T,cas=1;
scanf("%d",&T_T);
while(T_T--)
{
for(int i=0;i<4;i++) p[i].input();
bool flag=false;
for(int i=1;i<4;i++)
{
if(flag==true) break;
for(int j=i+1;j<4;j++)
{
if(flag==true) break;
for(int k=1;k<4;k++)
{
if(flag==true) break;
if(k==i||k==j) continue;
flag=check(i,j,k);
}
}
}
if(flag==true) printf("Case #%d: Yes\n",cas++);
else printf("Case #%d: No\n",cas++);
}
return 0;
}
HDOJ 5206 Four Inages Strategy 暴力+几何
原文:http://blog.csdn.net/ck_boss/article/details/45126743