Four Inages Strategy
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 387 Accepted Submission(s): 155
Problem Description
Young F found a secret record which inherited from ancient times in ancestral home by accident, which named "Four Inages Strategy". He couldn‘t restrain inner exciting, open the record, and read it carefully. " Place four magic stones
at four points as array element in space, if four magic stones form a square, then strategy activates, destroying enemy around". Young F traveled to all corners of the country, and have collected four magic stones finally. He placed four magic stones at four
points, but didn‘t know whether strategy could active successfully. So, could you help him?
Input
Multiple test cases, the first line contains an integer
T(no
more than 10000),
indicating the number of cases. Each test case contains twelve integers
x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,|x|,|y|,|z|≤100000,representing
coordinate of four points. Any pair of points are distinct.
Output
For each case, the output should occupies exactly one line. The output format is Case #x:
ans,
here x
is the data number begins at 1,
if your answer is yes,ans
is Yes, otherwise ans
is No.
Sample Input
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
Sample Output
Case #1: Yes Case #2: No
Source
题意:给你三维四个点的坐标
思路,,枚举X1的邻点,共三种情况。然后判断是否边是否垂直,长度是否相等。。
容易得到,第四个坐标,为枚举的两个点坐标加起来减去x1的坐标。然后判断就好
#include <cstdio> #include <algorithm> #include <map> #include <cstring> #include <cmath> #include <iostream> using namespace std; #define lson l , m , rt << 1 #define rson m + 1 , r , rt << 1 | 1 #define LL __int64 typedef long long ll; #define PI 3.1415926 #define eps 1e-7 double dist(double a,double b,double c,double a1,double b1,double c1) { return sqrt((a-a1)*(a-a1)+(b-b1)*(b-b1)+(c-c1)*(c-c1)); } int main() { int t,i,j,k,p; int Case=0; cin>>t; while(t--) { double x1[4]; double x2[4]; double x3[4]; double x4[4]; double x,y,z; cin>>x1[0]>>x1[1]>>x1[2]>>x2[0]>>x2[1]>>x2[2]>>x3[0]>>x3[1]>>x3[2]>>x4[0]>>x4[1]>>x4[2]; int flag=0; //枚举x1的三种邻点情况。 if(((x1[0]-x3[0])*(x1[0]-x2[0])+(x1[1]-x3[1])*(x1[1]-x2[1])+(x1[2]-x3[2])*(x1[2]-x2[2]))==0&&dist(x1[0],x1[1],x1[2],x2[0],x2[1],x2[2])==dist(x1[0],x1[1],x1[2],x3[0],x3[1],x3[2])) { x=x2[0]+x3[0]-x1[0]; y=x2[1]+x3[1]-x1[1]; z=x2[2]+x3[2]-x1[2]; if(x==x4[0]&&y==x4[1]&&z==x4[2]) flag=1; } if(((x1[0]-x4[0])*(x1[0]-x2[0])+(x1[1]-x4[1])*(x1[1]-x2[1])+(x1[2]-x4[2])*(x1[2]-x2[2]))==0&&dist(x1[0],x1[1],x1[2],x2[0],x2[1],x2[2])==dist(x1[0],x1[1],x1[2],x4[0],x4[1],x4[2])) { x=x2[0]+x4[0]-x1[0]; y=x2[1]+x4[1]-x1[1]; z=x2[2]+x4[2]-x1[2]; if(x==x3[0]&&y==x3[1]&&z==x3[2]) flag=1; } if(((x1[0]-x4[0])*(x1[0]-x3[0])+(x1[1]-x4[1])*(x1[1]-x3[1])+(x1[2]-x4[2])*(x1[2]-x3[2]))==0&&dist(x1[0],x1[1],x1[2],x3[0],x3[1],x3[2])==dist(x1[0],x1[1],x1[2],x4[0],x4[1],x4[2])) { x=x3[0]+x4[0]-x1[0]; y=x3[1]+x4[1]-x1[1]; z=x3[2]+x4[2]-x1[2]; if(x==x2[0]&&y==x2[1]&&z==x2[2]) flag=1; } cout<<"Case #"<<++Case<<":"<<" "; if(flag) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }