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 #include<iostream>
 4 #include<string>
 5 #include<algorithm>
 6 #include<cmath>
 7 #include<queue>
 8 #include<stack>
 9 #include<vector>
10 #define eps 1e-9
11 #define maxn
12 using namespace std;
13 typedef long long LL;
14 struct Node
15 {
16     long long  x,y,z;
17 };
18 Node p[5];
19 double dist(int a,int b)
20 {
21     double cha1=(double)p[a].x-p[b].x;
22     double cha2=(double)p[a].y-p[b].y;
23     double cha3=(double)p[a].z-p[b].z;
24     return (sqrt(cha1*cha1+cha2*cha2+cha3*cha3));
25 }
26 int puan(int a,int b,int c)
27 {
28     LL x1=p[b].x-p[a].x;
29     LL y1=p[b].y-p[a].y;
30     LL z1=p[b].z-p[a].z;
31
32     LL x2=p[b].x-p[c].x;
33     LL y2=p[b].y-p[c].y;
34     LL z2=p[b].z-p[c].z;
35     if(x1*x2+y1*y2+z1*z2==0)
36         return 1;
37     return 0;
38
39 }
40 int solve()
41 {
42     double tem1,tem2,tem3,tem4;
43     tem1=dist(1,2);
44     tem2=dist(2,3);
45     tem3=dist(3,4);
46     tem4=dist(4,1);
47     //printf("%lf %lf %lf %lf==\n",tem1,tem2,tem3,tem4);
48     if(fabs(tem1-tem2)<eps&&fabs(tem2-tem3)<eps&&fabs(tem3-tem4)<eps&&puan(1,2,3))
49         return 1;
50     tem1=dist(1,2);
51     tem2=dist(2,4);
52     tem3=dist(4,3);
53     tem4=dist(3,1);
54     if(fabs(tem1-tem2)<eps&&fabs(tem2-tem3)<eps&&fabs(tem3-tem4)<eps&&puan(1,2,4))
55         return 1;
56     tem1=dist(1,3);
57     tem2=dist(3,2);
58     tem3=dist(2,4);
59     tem4=dist(4,1);
60     if(fabs(tem1-tem2)<eps&&fabs(tem2-tem3)<eps&&fabs(tem3-tem4)<eps&&puan(1,3,2))
61         return 1;
62     tem1=dist(1,3);
63     tem2=dist(3,4);
64     tem3=dist(4,2);
65     tem4=dist(2,1);
66      // printf("%lf %lf %lf %lf==\n",tem1,tem2,tem3,tem4);
67     if(fabs(tem1-tem2)<eps&&fabs(tem2-tem3)<eps&&fabs(tem3-tem4)<eps&&puan(1,3,4))
68         return 1;
69     tem1=dist(1,4);
70     tem2=dist(4,2);
71     tem3=dist(2,3);
72     tem4=dist(3,1);
73     if(fabs(tem1-tem2)<eps&&fabs(tem2-tem3)<eps&&fabs(tem3-tem4)<eps&&puan(1,4,2))
74         return 1;
75     tem1=dist(1,4);
76     tem2=dist(4,3);
77     tem3=dist(3,2);
78     tem4=dist(2,1);
79     if(fabs(tem1-tem2)<eps&&fabs(tem2-tem3)<eps&&fabs(tem3-tem4)<eps&&puan(1,4,3))
80         return 1;
81     return 0;
82 }
83 int main()
84 {
85     int t;
86     scanf("%d",&t);
87     for(int ii=1; ii<=t; ii++)
88     {
89         for(int i=1; i<=4; i++)
90             scanf("%I64d %I64d %I64d",&p[i].x,&p[i].y,&p[i].z);
91         printf("Case #%d: ",ii);
92         if(solve())
93             printf("Yes\n");
94         else
95             printf("No\n");
96
97     }
98     return 0;
99 }
时间: 2024-10-27 11:46:16

hdu 5206 Four Inages Strategy的相关文章

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

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 secr

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

hdu 5206 判断三维空间中的四个点是否构成正方形

题目描述:如标题 思路:一比一比根号二咯 1 #include <algorithm> 2 #include <iostream> 3 #include <string> 4 using namespace std; 5 6 const int N = 4; 7 8 struct Node 9 { 10 int x, y, z; 11 } node[N]; 12 13 inline long long square( int k ) 14 { 15 return ( l

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

hdu 1536 S-Nim 博弈论,,求出SG&#39;函数就可以解决

S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4975    Accepted Submission(s): 2141 Problem Description Arthur and his sister Caroll have been playing a game called Nim for some time now

HDU S-Nim(博弈 SG)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1536 Problem Description Arthur and his sister Caroll have been playing a game called Nim for some time now. Nim is played as follows: The starting position has a number of heaps, all containing some, no

HDU 5882 Balanced Game

Balanced Game Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 508    Accepted Submission(s): 428 Problem Description Rock-paper-scissors is a zero-sum hand game usually played between two people