# Four Inages Strategy

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1092    Accepted Submission(s): 394

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 #xans, 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

（其实就跟卿神的思路一样了）

AC代码：

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
struct dist
{
long long length;
int i, j;
}dis[6];
bool compare(dist a, dist b)
{
if (a.length < b.length) return 1;
else return 0;
}
int main()
{
int t;
cin >> t;
for (int cnt = 1; cnt <= t; cnt++)
{
long long x[4], y[4], z[4];
int edge[4], diag[2], repeat = 0, flag = 0;
for (int i = 0; i < 4; i++)
scanf("%I64d %I64d %I64d", &x[i], &y[i], &z[i]);
for (int i = 0; i < 3; i++)
for (int j = i+1; j < 4;j++)
if (x[i] == x[j] && y[i] == y[j] && z[i] == z[j])
{
repeat = 1; break;
}
if (repeat == 1)
{
printf("Case #%d: No\n", cnt);
continue;
}
for (int i = 0, p = 0; i < 3; i++)
for (int j = i+1; j < 4; j++)
{
dis[p].i = i; dis[p].j = j;
dis[p++].length = (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(dis, dis + 6, compare);
/*		long long min = dis[0].length, max = dis[5].length;
int maxc = 0, minc = 0;
for (int i = 0; i < 6; i++)
{
if (dis[i].length == min) minc++;
if (dis[i].length == max) maxc++;
}
if (minc != 4 && maxc != 4)
{
printf("Case #%d: No\n", cnt);
continue;
}
if (minc == 4&&maxc == 2)
{
for (int i = 0,p=0,q=0; i < 6; i++)
{
if (dis[i].length == min) edge[p++] = i;
else diag[q++] = i;
}
}
else if (maxc == 4&&minc == 2)
{
for (int i = 0, p = 0, q = 0; i < 6; i++)
{
if (dis[i].length == max) edge[p++] = i;
else diag[q++] = i;
}
}
else
{
printf("Case #%d: No\n", cnt);
continue;
}
if (dis[diag[0]].length != dis[diag[1]].length)
{
printf("Case #%d: No\n", cnt);
continue;
}
int diag1 = dis[diag[0]].i, diag2 = dis[diag[0]].j, diag3 = dis[diag[1]].i, diag4 = dis[diag[1]].j;
if ((x[diag1] - x[diag2])*(x[diag3] - x[diag4]) + (y[diag1] - y[diag2])*(y[diag3] - y[diag4]) + (z[diag1] - z[diag2])*(z[diag3] - z[diag4]))
{
printf("Case #%d: No\n", cnt);
continue;
}
*/
for (int i = 0; i < 6; i++)
cout << dis[i].length << " ";
cout << endl;
if (dis[0].length == dis[1].length&&dis[1].length == dis[2].length&&dis[2].length == dis[3].length&&dis[3].length * 2 == dis[4].length&&dis[4].length == dis[5].length)
printf("Case #%d: Yes\n", cnt);
else printf("Case #%d: No\n", cnt);
}
//	system("pause");
return 0;
}

• 本文已收录于以下专栏：

## Four Inages Strategy hdu 5206

Four Inages Strategy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot...
• zufejsjcy
• 2015年04月18日 21:51
• 193

## hdu 5206 Four Inages Strategy

Four Inages Strategy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot...
• acm_BaiHuzi
• 2015年04月19日 00:03
• 507

## HDU 5206 Four Inages Strategy

#include "string" #include "iostream" #include "cstdio" #include "cmath" #include "set" #include "qu...
• secretbase_
• 2015年04月18日 21:48
• 441

## HDOJ 5206 Four Inages Strategy 暴力+几何

• u012797220
• 2015年04月19日 10:07
• 604

## 【HDU 5206】Four Inages Strategy —— 计算几何之空间正方形

• treasuresss
• 2015年04月21日 23:40
• 338

## hdu 5206 Four Inages Strategy【计算几何】【判断空间正方形】

Four Inages Strategy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot...
• mengxiang000000
• 2016年02月04日 18:11
• 287

## Four Inages Strategy

Four Inages Strategy
• Yuric
• 2015年04月20日 21:42
• 296

## BestCoder Round 38-1001 Four Inages Strategy

• David_Jett
• 2015年04月18日 22:31
• 516

## hdu 5206:Four Inages Strategy（判断四个点能否组成正方形）

• cacyth
• 2015年05月01日 16:32
• 575

## hdu 5938 Four Operations【贪心】

Four Operations Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)...
• mengxiang000000
• 2016年10月29日 16:47
• 888

举报原因： 您举报文章：HDU 5206 Four Inages Strategy（几何题） 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)