一蓑烟雨任平生

学无止境

HDU 5206 Four Inages Strategy(几何题)

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


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/code12hour/article/details/46823567
文章标签: 算法 几何题 HDU
个人分类: 数学 HDOJ
上一篇CDOJ 763 树上的鸟儿(水题/模拟题)
下一篇CDOJ_1063 秋实大哥与妹纸(堆结构)
想对作者说点什么? 我来说一句

Four Inages Strategy

Four Inages Strategy

Yuric Yuric

2015-04-20 21:42:17

阅读数:336

没有更多推荐了,返回首页

关闭
关闭