Four Inages Strategy
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1395 Accepted Submission(s): 478
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
这个题真的能看出新手和老兵油子的差距:
我方智障思路:判断共面,然后求出所有点之间6个点的距离,其中有4个相等就可以了~WA一发、然后想了想,啊、应该是4个相等,并且另外两个相等,再WA一发、啊、对了,还得判断直角、然后辛苦写完了代码、还是WA,至于为什么呢?6条边的距离不是用两层for来求的,我是直接枚举的点,然后就没有然后了...........
大牛神级思路:直接用两层for,求六条边的距离,然后sort一下,前4个要相等,后两个要相等,并且根据勾股定理要满足是直角、(juli[0]*2==juli[5])因为这里求根号的数据有可能带有误差,所以直接用平方代表、
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long int
ll x[5],y[5],z[5];
ll juli[10];
int main()
{
int t;
int kase=0;
scanf("%d",&t);
while(t--)
{
for(int i=0;i<4;i++)
{
scanf("%I64d%I64d%I64d",&x[i],&y[i],&z[i]);
}
int cont=0;
for(int i=0;i<4;i++)
{
for(int j=i+1;j<4;j++)
{
// printf("%I64d\n",(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])+(z[i]-z[j])*(z[i]-z[j]));
juli[cont++]=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])+(z[i]-z[j])*(z[i]-z[j]);
}
}
sort(juli,juli+cont);
if(juli[0]==juli[1]&&juli[1]==juli[2]&&juli[2]==juli[3]&&juli[4]==juli[5]&&juli[0]*2==juli[5])//满足就yes
{
printf("Case #%d: Yes\n",++kase);
}
else//不满足就no
{
printf("Case #%d: No\n",++kase);
}
}
}