题目链接:HDU - 5206

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.
题意描述:给出四个三维坐标位置,判断这四个点能否构成一个正方形。
算法分析:比赛的时候刚开始想到正方形边边相等,然后四角90度,这样的方法搞到一半的时候想了想有点麻烦呀,后来仔细想了想,突然意识到正方形里每个顶点到其他三个顶点距离的关系:对角线距离*对角线距离=2*边*边。然后就OK啦。
 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#define inf 0x7fffffff
using namespace std;
typedef long long LL;
const LL maxn=+; LL n,m;
struct Point
{
LL x,y,z;
Point (LL x=,LL y=,LL z=):x(x),y(y),z(z){}
}a,b,c,d;
typedef Point Vector; double Dot(Vector A,Vector B) {return A.x*B.x + A.y*B.y; }
double Length(Vector A) {return sqrt(Dot(A,A)); }
double angle(Vector A,Vector B) {return acos(Dot(A,B)/Length(A)/Length(B)); } LL dis(Point A,Point B)
{
LL xx=(A.x-B.x)*(A.x-B.x);
LL yy=(A.y-B.y)*(A.y-B.y);
LL zz=(A.z-B.z)*(A.z-B.z);
return xx+yy+zz;
} int main()
{
int t,ncase=;
scanf("%d",&t);
while (t--)
{
scanf("%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d",
&a.x,&a.y,&a.z,&b.x,&b.y,&b.z,&c.x,&c.y,&c.z,&d.x,&d.y,&d.z);
//scanf("%d%d%d%d%d%d%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2,&x3,&y3,&z3,&x4,&y4,&z4);
int flag=;
LL len,len2,len3;
len=dis(a,b) ;len2=dis(a,c) ;len3=dis(a,d) ;
if ((len==len2&&len3==len+len2)||(len==len3&&len2==len+len3)||(len2==len3&&len==len2+len3))
flag++;
len=dis(b,a) ;len2=dis(b,c) ;len3=dis(b,d) ;
if ((len==len2&&len3==len+len2)||(len==len3&&len2==len+len3)||(len2==len3&&len==len2+len3))
flag++;
len=dis(c,a) ;len2=dis(c,b) ;len3=dis(c,d) ;
if ((len==len2&&len3==len+len2)||(len==len3&&len2==len+len3)||(len2==len3&&len==len2+len3))
flag++;
len=dis(d,a) ;len2=dis(d,b) ;len3=dis(d,c) ;
if ((len==len2&&len3==len+len2)||(len==len3&&len2==len+len3)||(len2==len3&&len==len2+len3))
flag++;
if (flag==) printf("Case #%d: Yes\n",ncase++);
else printf("Case #%d: No\n",ncase++);
}
return ;
}
 
 

hdu 5206 Four Inages Strategy 计算几何的更多相关文章

  1. hdu 5206 Four Inages Strategy 判断是否是正方形

    Four Inages Strategy Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem. ...

  2. HDU 5206 Four Inages Strategy 水题

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5206 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  3. hdu 5206 Four Inages Strategy

    题目大意: 判断空间上4个点是否形成一个正方形 分析: 标称思想 : 在p2,p3,p4中枚举两个点作为p1的邻点,不妨设为pi,pj,然后判断p1pi与p1pj是否相等.互相垂直,然后由向量法,最后 ...

  4. hdu 2393:Higher Math(计算几何,水题)

    Higher Math Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. HDU 5839 Special Tetrahedron (计算几何)

    Special Tetrahedron 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n points ...

  6. [BC]Four Inages Strategy(三维空间判断正方形)

    题目连接 :http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=577&pid=1001 题目大意:在三维空间中, ...

  7. hdu 5784 How Many Triangles 计算几何,平面有多少个锐角三角形

    How Many Triangles 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5784 Description Alice has n poin ...

  8. HDU 4606 Occupy Cities (计算几何+最短路+二分+最小路径覆盖)

    Occupy Cities Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  9. HDU 6351暴力枚举 6354计算几何

    Beautiful Now Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

随机推荐

  1. [译]16-spring基于注解的配置元数据

    从spring2.5起spring框架开始支持java注解的配置元数据.所以除了使用xml配置文件来描述bean的装配之外,你还 可以使用基于java注解的配置元数据来完成同样的功能. spring框 ...

  2. Oracle 遇到的问题:dos命令下imp导入数据时出错

    赋予用户dba权限:很多情况下会遇到没有权限需要输入用户名及密码才能导入 --已知被赋予权限的用户名为:batch --第一步 登陆 sqlplus /nolog sql>conn /as sy ...

  3. [转载]kd tree

    [本文转自]http://www.cnblogs.com/eyeszjwang/articles/2429382.html k-d树(k-dimensional树的简称),是一种分割k维数据空间的数据 ...

  4. 历届试题 带分数 全排列模板 JAVA

    标题:带分数 100 可以表示为带分数的形式:100 = 3 + 69258 / 714 还可以表示为:100 = 82 + 3546 / 197 注意特征:带分数中,数字1~9分别出现且只出现一次( ...

  5. 啥叫sched-domain

    这周问过公司里专家,说cpu-load是说CPU的计算能力,但是从代码实在不知道cpu-load说的是啥! SD_SHARE_CPUPOWER 0X8000  domain的成员共享cpu power ...

  6. gulp实时刷新页面

    需要安装nodejs 全局安装gulp cnpm install -g gulp 局部安装 cnpm install -save-dev gulp 添加配置文件,新建gulpfile.js var g ...

  7. js加解密的算法

    //字符串和数字互转 var str="a" var r = str.charCodeAt(0); //97 10进制 console.log(r); var t=String.f ...

  8. ftp无法连接的原因

    1.需求 记录碰到的ftp无法连接的原因 2.解决方案 .确认ftp服务开启. .确认21端口没有被占用. .确认有目录的执行权限. .确认配置文件中的目录读写权限正确. .关闭SELinux 修改/ ...

  9. 原生方法scrollTo支持滚动特效

    scrollTo默认的是瞬间滚动到坐标位置, 使用配置方法, behavior属性设置为smooth就可以支持平滑滚动了,不过这种方法兼容性不行,并且无法支持配置滚动速率 // 默认滚动效果,瞬时滚动 ...

  10. php 字符串重要函数

    1.chop() 从字符串右端移除字符 chop(string,charlist) $str="hello world~"; echo chop($str,"ld~&qu ...