HDOJ 5206 Four Inages Strategy 暴力+几何

枚举两个点当做0号点的相邻两边,判断两边长度是否相等和垂直,然后用向量推最后一个点,比较是否相等

Four Inages Strategy

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 375    Accepted Submission(s): 150

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 #x: ans,
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

Source

BestCoder Round #38 ($)

/* ***********************************************
Author        :CKboss
Created Time  :2015年04月19日 星期日 08时52分45秒
File Name     :A.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef long long int LL;

struct Point
{
	LL x,y,z;
	void input() { cin>>x>>y>>z; }
	LL len() { return x*x+y*y+z*z; }
}p[4];

bool check(int a,int b,int c)
{
	Point pp1 = (Point){p[a].x-p[0].x,p[a].y-p[0].y,p[a].z-p[0].z};
	Point pp2 = (Point){p[b].x-p[0].x,p[b].y-p[0].y,p[b].z-p[0].z};
	Point pp3 = (Point){pp1.x-pp2.x,pp1.y-pp2.y,pp1.z-pp2.z};

	LL Len1=pp1.len();
	LL Len2=pp2.len();
	LL Len3=pp3.len();

	if(Len1!=Len2) return false;
	if(Len1+Len2!=Len3) return false;

	LL dx=p[a].x+p[b].x-p[0].x;
	LL dy=p[a].y+p[b].y-p[0].y;
	LL dz=p[a].z+p[b].z-p[0].z;

	if(dx==p[c].x&&dy==p[c].y&&dz==p[c].z) return true;
	return false;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

	int T_T,cas=1;
	scanf("%d",&T_T);
	while(T_T--)
	{
		for(int i=0;i<4;i++) p[i].input();
		bool flag=false;
		for(int i=1;i<4;i++)
		{
			if(flag==true) break;
			for(int j=i+1;j<4;j++)
			{
				if(flag==true) break;
				for(int k=1;k<4;k++)
				{
					if(flag==true) break;
					if(k==i||k==j) continue;
					flag=check(i,j,k);
				}
			}
		}
		if(flag==true) printf("Case #%d: Yes\n",cas++);
		else printf("Case #%d: No\n",cas++);
	}

    return 0;
}
时间: 2024-10-12 23:00:52

HDOJ 5206 Four Inages Strategy 暴力+几何的相关文章

hdu 5206 Four Inages Strategy

题目大意: 判断空间上4个点是否形成一个正方形 分析: 标称思想 : 在p2,p3,p4中枚举两个点作为p1的邻点,不妨设为pi,pj,然后判断p1pi与p1pj是否相等.互相垂直,然后由向量法,最后一个点坐标应该为pi+pj−p1,判断是否相等就好了. 我的思想 : 枚举了各种情况,4条边相等+有一个角是直角.后来想想,因为是在三维中,有可能4个点不共面,这点没想到,不过这道题AC了,估计数据水了 1 #include<cstdio> 2 #include<cstring> 3

hdu 5206 Four Inages Strategy(计算几何)

题意:给出空间中四个点的坐标 判断能否组成正方形 思路:这题需要注意的是 空间而不是平面 就算是四边相等 对角线相等也不一定就是正方形 还需要通过向量判断对边是否平行 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define ll __int64 //#define ll long long struct nod

hdu 5206 Four Inages Strategy (空间向量)

中文题目:<四象阵法> 判断空间四点能否组成正方形. 一次AC,好激动~ #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <cmath> typedef long long ll; using namespace std; struct point{ int x,y,z; }; bool isequal(poi

BestCoder Round #38 1001 Four Inages Strategy 暴力

题意:给你空间中四个点,问你这四个点能否组成正方形. 解题思路:看两两之间的距离.根据正方形的性质求解. 解题代码: 1 // File Name: c.cpp 2 // Author: darkdream 3 // Created Time: 2014年10月07日 星期二 00时41分28秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include&l

hdoj 2050 折线分割平面 【几何模板】

折线分割平面 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17229    Accepted Submission(s): 11890 Problem Description 我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目.比如,一条折线可以将平面分成两部分,两条折线最多可以将平

HDOJ 5128 The E-pang Palace 暴力枚举+计算几何

枚举出每一个矩形,判断相交 如果是回字型则输出大的矩形的面积.......... The E-pang Palace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 73    Accepted Submission(s): 26 Problem Description E-pang Palace was built in Qin

HDU 5206

 Four Inages Strategy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 387    Accepted Submission(s): 155 Problem Description Young F found a secret record which inherited from ancient times i

TOJ 1203: Number Sequence

1203: Number Sequence Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByte Total Submit: 957            Accepted:208 Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Gi

hdoj 4932 Miaomiao&#39;s Geometry 【暴力枚举】

题意:在一条直线上有n个点,取一长度差为x的区间, 规定点必须是区间的端点, 让你找出来最大的x 策略:rt 分析可得:两个相邻点之间的区间要么是两个点的差,要么就是两个点的差的一半,那我们就简单枚举一下就好了 排好序之后再枚举 代码: #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define M 200 using namespace std; do