码迷,mamicode.com
首页 > 其他好文 > 详细

HDOJ 5206 Four Inages Strategy 暴力+几何

时间:2015-04-19 11:39:56      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:


枚举两个点当做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 #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
 

Source
 



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


HDOJ 5206 Four Inages Strategy 暴力+几何

标签:

原文地址:http://blog.csdn.net/ck_boss/article/details/45126743

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!