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<deque>
10 #include<stack>
11 #include<bitset>
12 #include<algorithm>
13 #include<functional>
14 #include<numeric>
15 #include<utility>
16 #include<sstream>
17 #include<iostream>
18 #include<iomanip>
19 #include<cstdio>
20 #include<cmath>
21 #include<cstdlib>
22 #include<cstring>
23 #include<ctime>
24 #define LL long long
25 #define eps 1e-8
26 using namespace std;
27 struct node{
28     double x,y,z;
29 };
30 node a[5];
31 double dis[5][5];
32 double thedis(double x1, double y1,double z1, double x2,double y2,double z2)
33 {
34   return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2) *(z1-z2)) ;
35 }
36 bool ok()
37 {
38    for(int i = 1;i <= 4;i ++)
39    {
40        for(int j= 1;j <= 4 ; j ++)
41        {
42             dis[i][j] = thedis(a[i].x,a[i].y,a[i].z,a[j].x,a[j].y,a[j].z);
43        }
44      sort(dis[i] + 1,dis[i] + 1 + 4);
45    }
46    for(int i = 2;i <= 4;i ++)
47        for(int j = 1;j <= 4; j ++)
48        {
49           if(fabs(dis[i][j] - dis[i-1][j]) > eps)
50               return 0 ; 
51        }
52    if(fabs(dis[1][4]-0 ) <eps)
53        return 0 ; 
54    if(fabs(dis[1][3] - dis[1][2]) > eps)
55        return 0 ;
56    if(fabs(dis[1][3] * sqrt(2) - dis[1][4]) > eps)
57        return 0 ;
58    if(fabs(dis[1][3] - 0 ) < eps)
59        return 0 ;
60    if(fabs(dis[1][2] - 0 ) < eps)
61        return 0 ;
62    return 1;
63 }
64 int main(){
65    int n; 
66    //freopen("A.in","r",stdin);
67    //freopen("A.out","w",stdout);
68    scanf("%d",&n);
69    for(int ca = 1 ; ca <= n ; ca ++)
70    {
71        for(int i= 1;i <= 4;i ++)
72           scanf("%lf %lf %lf",&a[i].x,&a[i].y,&a[i].z);
73        printf("Case #%d: ",ca);
74        if(ok())
75        {
76          printf("Yes\n");
77        }else {
78          printf("No\n");
79        }
80    }
81 return 0;
82 }
View Code

 

转载于:https://www.cnblogs.com/zyue/p/4438734.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值