题目链接: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. python中的字符问题

    unicode/unicodebig/utf8 在python上默认情况下都解析不了 window系统中 ASCLL对应的是GBK unicode|unicodebigendian 对应 utf-16 ...

  2. ssh-centos74.sh

    #!/bin/bash sed -i 's/#PermitRootLogin yes/PermitRootLogin yes/g' /etc/ssh/sshd_config sed -i 's/#Us ...

  3. Leetcode 664.奇怪的打印机

    奇怪的打印机 有台奇怪的打印机有以下两个特殊要求: 打印机每次只能打印同一个字符序列. 每次可以在任意起始和结束位置打印新字符,并且会覆盖掉原来已有的字符. 给定一个只包含小写英文字母的字符串,你的任 ...

  4. [oldboy-django][2深入django]点击刷新验证码

    # 点击更新验证码,只要重新在发送一个请求即可 <img src="/check_code/" onclick="updateCode(this);" w ...

  5. poj 3436 网络流构图经典

    ACM Computer Factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6012   Accepted: 2 ...

  6. [bzoj4361] isn [树状数组+dp+容斥原理]

    题面 传送门 思路 首先,本题目的核心元素是非降子序列,而显然这个题目中的子序列只和序列的长度.位置,以及互相之间的包含关系,这些东西相关 所以我们可以依据这些先"猜"(实际上是估 ...

  7. phantomjs和selenium模拟登陆qq空间

    # -*- coding: utf-8 -*- from selenium import webdriver import time driver =webdriver.PhantomJS() dri ...

  8. ubuntu上安装ffmpeg

      安装包和主要步骤: 1. 首先安装系统基础环境 RHEL & CentOS 系列:yum install -y automake autoconf libtool gcc gcc-c++ ...

  9. js剪贴板操作

    这是一个很有意思的地方,很多不了解的人或者初级的js编程者会觉得很不可思议,js都那么强大了,访问剪贴板一个粘贴复制,大概就是一行命令的事情,但是事实如此,js对于访问本地计算机的剪贴板的支持其实是十 ...

  10. 结构型设计模式之外观模式(Facade)

    结构 意图 为子系统中的一组接口提供一个一致的界面,F a c a d e 模式定义了一个高层接口,这个接口使得这一子系统更加容易使用. 适用性 当你要为一个复杂子系统提供一个简单接口时.子系统往往因 ...