HDU 5206,hdu5206
Four Inages StrategyTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 387 Accepted Submission(s): 155
Problem DescriptionYoung 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?
InputMultiple test cases, the first line contains an integerT(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.
OutputFor 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
20 0 0 0 1 0 1 0 0 1 1 01 1 1 2 2 2 3 3 3 4 4 4
Sample Output
Case #1: YesCase #2: No
SourceBestCoder Round #38 ($)
題意:給你三維四個點的座標,讓你求出是否能構成一個正方形
思路,,枚舉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 __int64typedef long long ll;#define PI 3.1415926#define eps 1e-7double 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;}