Four Inages Strategy
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 664 Accepted Submission(s): 259
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
解题报告:
简单的判断即可。
#include <iostream>
#include <stdio.h>
using namespace std;
typedef long long ll;
ll x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4;
void exchange(ll& x,ll& y,ll& z,ll& xx,ll& yy,ll& zz){
ll tmpx,tmpy,tmpz;
tmpx=x,tmpy=y,tmpz=z;
x=xx;y=yy;z=zz;
xx=tmpx,yy=tmpy,zz=tmpz;
}
bool is90(ll x,ll y,ll z,ll xx,ll yy,ll zz ){
return x*xx+y*yy+z*zz==0;
}
bool isPall(ll x,ll y,ll z,ll xx,ll yy,ll zz){
return (x*yy==y*xx && x*zz==z*xx && y*zz==z*yy);
}
bool isEqual(ll x,ll y,ll z,ll xx,ll yy,ll zz){
return x*x+y*y+z*z==xx*xx+yy*yy+zz*zz;
}
int main()
{
int T,i=0;
cin>>T;
while(++i,T--)
{
scanf("%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d",&x1,&y1,&z1,
&x2,&y2,&z2,&x3,&y3,&z3,&x4,&y4,&z4);
if( is90(x2-x1,y2-y1,z2-z1,x3-x1,y3-y1,z3-z1) ){;}
else if(is90(x1-x2,y1-y2,z1-z2,x3-x2,y3-y2,z3-z2)){exchange(x2,y2,z2,x1,y1,z1);}
else if(is90(x1-x3,y1-y3,z1-z3,x2-x3,y2-y3,z2-z3)){exchange(x3,y3,z3,x1,y1,z1);}
else { printf("Case #%d: No\n",i);continue; }
if( !is90(x2-x4,y2-y4,z2-z4,x3-x4,y3-y4,z3-z4) ) printf("Case #%d: No\n",i);
else{
if( isPall(x2-x1,y2-y1,z2-z1,x4-x3,y4-y3,z4-z3) &&
isEqual(x2-x1,y2-y1,z2-z1,x3-x1,y3-y1,z3-z1) )
printf("Case #%d: Yes\n",i);
else printf("Case #%d: No\n",i);
}
}
}

本博客讨论了如何通过四个不同坐标点判断四象限魔法石策略是否激活,涉及几何和数学逻辑。
637

被折叠的 条评论
为什么被折叠?



