HDU 5206 Four Inages Strategy(几何题)

原创 2015年07月09日 23:42:05

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


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

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

原题链接 Four Inages Strategy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65...

Four Inages Strategy hdu 5206

Four Inages Strategy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot...

HDU 5206 Four Inages Strategy

题意:给出三维空间中的4个点 判断能否组成正方形 比赛时直接套的三维几何的版子 判断3个向量中 是否有两个相等 垂直 且和为第三个向量  其实可以算出他们两两之间距离 排个序 看小的四个是否相等(...

HDU5206-Four Inages Strategy

Problem Description Young F found a secret record which inherited from ancient times in ancestral h...

BestCoder Round 38-1001 Four Inages Strategy

题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=577&pid=1001 题面: Four Ina...

Four Inages Strateg

Four Inages Strategy    Accepts: 186    Submissions: 1374  Time Limit: 2000/1000 MS (Java/Others)  ...
  • wyh7280
  • wyh7280
  • 2015年04月18日 21:09
  • 346

hdu 5938 Four Operations(复杂的模拟题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5938 Four Operations Time Limit: 2000/1000 ...

HDU 5206

Four Inages Strategy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth...

hdu5938 Four Operations(贪心)

Four Operations Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

HDU 5938 Four Operations 【贪心】(2016年中国大学生程序设计竞赛(杭州))

Four Operations Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:HDU 5206 Four Inages Strategy(几何题)
举报原因:
原因补充:

(最多只允许输入30个字)