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

hdu 5206 Four Inages Strategy

时间:2015-04-19 08:55:47      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:hdu 5206 four inages

Four Inages Strategy

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 331    Accepted Submission(s): 128


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
 

题意:

给你四个三维坐标点(x1,y1,z1),判断这四个点能否组成一个正方形。


题解:

吧每两个点的边长先算出来,排序,判断。


#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<map>
#include<cmath>

using namespace std;

int n;
long long x[4];
long long y[4];
long long z[4];
long long a[10];
int  main() {
    int t;
    cin>>t;
    int ca=1;
    while(t--) {
        for(int i=0; i<4; i++)
            scanf("%I64d%I64d%I64d",&x[i],&y[i],&z[i]);
        int l=0;
        for(int i=0; i<4; i++) {
            for(int j=i+1; j<4; j++) {
                a[l++]=(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(a,a+l);
        if(a[0]==a[1]&&a[1]==a[2]&&a[2]==a[3]&&a[4]==a[5]&&(a[1]+a[2]==a[5])) {
            printf("Case #%d: Yes\n",ca++);
        } else
            printf("Case #%d: No\n",ca++);
    }
}


hdu 5206 Four Inages Strategy

标签:hdu 5206 four inages

原文地址:http://blog.csdn.net/acm_baihuzi/article/details/45119559

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