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


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

Four Inages Strategy hdu 5206

Four Inages Strategy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot...
  • zufejsjcy
  • 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
  • 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_
  • secretbase_
  • 2015年04月18日 21:48
  • 441

HDOJ 5206 Four Inages Strategy 暴力+几何

枚举两个点当做0号点的相邻两边,判断两边长度是否相等和垂直,然后用向量推最后一个点,比较是否相等 Four Inages Strategy Time Limit: 2000/1000 MS...
  • u012797220
  • u012797220
  • 2015年04月19日 10:07
  • 604

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

原题链接 Four Inages Strategy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65...
  • treasuresss
  • 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
  • mengxiang000000
  • 2016年02月04日 18:11
  • 287

Four Inages Strategy

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

BestCoder Round 38-1001 Four Inages Strategy

题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=577&pid=1001 题面: Four Ina...
  • David_Jett
  • David_Jett
  • 2015年04月18日 22:31
  • 516

hdu 5206:Four Inages Strategy(判断四个点能否组成正方形)

小F在祖屋中意外发现一本上古时代传承下来的秘籍,名为《四象阵法》,他按捺不住内心的激动,翻开秘籍,一字一句地读了起来,“用四块元石作为阵基摆放在空间四处位置,如果四块元石形成一个正方形,则阵法激活,有...
  • cacyth
  • 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
  • mengxiang000000
  • 2016年10月29日 16:47
  • 888
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:HDU 5206 Four Inages Strategy(几何题)
举报原因:
原因补充:

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