Chinese title: "Four Elephant Zhenfa"
Determine whether the space four points can form a square.
One AC, so excited ~
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include < Cmath>typedef Long Long ll;using namespace std;struct point{int x, Y, z;}; BOOL IsEqual (Point P1,point p2,point p3,point p4) {int A=pow (p2.x-p1.x, 2) +pow (p2.y-p1.y,2) +pow (p2.z-p1.z,2); int B=pow ( p4.x-p3.x, 2) +pow (p4.y-p3.y,2) +pow (p4.z-p3.z,2); return a==b;} BOOL Isvertical (Point P1,point p2,point p3,point p4) {p1.x=p2.x-p1.x;p1.y=p2.y-p1.y;p1.z=p2.z-p1.z;p3.x=p4.x-p3.x; P3.y=p4.y-p3.y;p3.z=p4.z-p3.z;int A=p1.x*p3.x+p1.y*p3.y+p1.z*p3.z;return a==0;} BOOL Istar (Point P1,point p2,point p3,point p4) {if (p2.x+p3.x-p1.x! = p4.x) return false;if (p2.y+p3.y-p1.y! = P4.y) return f Alse;if (p2.z+p3.z-p1.z! = p4.z) return False;return true;} int main () {point p[5];int t;scanf ('%d ', &t), for (int. cs=1;cs<=t;cs++) {printf ("Case #%d:", CS); for (int i=1;i<= 4;++i) {scanf ("%d", &p[i].x), scanf ("%d", &p[i].y), scanf ("%d", &p[i].z);} if (IsEqual (p[1],p[2],p[1],p[3)) && isvertical (p[1],p[2], P[1],p[3]) {if (Istar (p[1],p[2],p[3],p[4])) printf ("yes\n");} else if (isequal (p[1],p[2],p[1],p[4]) && isvertical (P[1],p[2],p[1],p[4])) {if (Istar (p[1],p[2],p[4],p[3])) printf ("yes\n");} else if (isequal (p[1],p[3],p[1],p[4]) && isvertical (P[1],p[3],p[1],p[4])) {if (Istar (p[1],p[3],p[4],p[2])) printf ("yes\n");} else{printf ("no\n");}} return 0;}
HDU 5206 four inages strategy (space vector)