248人阅读 评论(0)

# 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;
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：52112次
• 积分：2284
• 等级：
• 排名：第17024名
• 原创：182篇
• 转载：6篇
• 译文：0篇
• 评论：1条
友情链接