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 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.

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

BestCoder Round #38 ($)

题意:给你三维四个点的坐标

思路,,枚举X1的邻点,共三种情况。然后判断是否边是否垂直,长度是否相等。。

容易得到,第四个坐标,为枚举的两个点坐标加起来减去x1的坐标。然后判断就好

#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define LL __int64
typedef long long ll;
#define PI 3.1415926
#define eps 1e-7
double dist(double a,double b,double c,double a1,double b1,double c1)
{
    return sqrt((a-a1)*(a-a1)+(b-b1)*(b-b1)+(c-c1)*(c-c1));
}
int main()
{
    int t,i,j,k,p;
    int Case=0;
    cin>>t;
    while(t--)
    {
        double x1[4];
        double x2[4];
        double x3[4];
        double x4[4];
        double x,y,z;
        cin>>x1[0]>>x1[1]>>x1[2]>>x2[0]>>x2[1]>>x2[2]>>x3[0]>>x3[1]>>x3[2]>>x4[0]>>x4[1]>>x4[2];
        int flag=0;
     //枚举x1的三种邻点情况。
        if(((x1[0]-x3[0])*(x1[0]-x2[0])+(x1[1]-x3[1])*(x1[1]-x2[1])+(x1[2]-x3[2])*(x1[2]-x2[2]))==0&&dist(x1[0],x1[1],x1[2],x2[0],x2[1],x2[2])==dist(x1[0],x1[1],x1[2],x3[0],x3[1],x3[2]))
        {
            x=x2[0]+x3[0]-x1[0];
            y=x2[1]+x3[1]-x1[1];
            z=x2[2]+x3[2]-x1[2];
            if(x==x4[0]&&y==x4[1]&&z==x4[2])
                flag=1;
        }
        if(((x1[0]-x4[0])*(x1[0]-x2[0])+(x1[1]-x4[1])*(x1[1]-x2[1])+(x1[2]-x4[2])*(x1[2]-x2[2]))==0&&dist(x1[0],x1[1],x1[2],x2[0],x2[1],x2[2])==dist(x1[0],x1[1],x1[2],x4[0],x4[1],x4[2]))
        {
            x=x2[0]+x4[0]-x1[0];
            y=x2[1]+x4[1]-x1[1];
            z=x2[2]+x4[2]-x1[2];
            if(x==x3[0]&&y==x3[1]&&z==x3[2])
                flag=1;
        }
        if(((x1[0]-x4[0])*(x1[0]-x3[0])+(x1[1]-x4[1])*(x1[1]-x3[1])+(x1[2]-x4[2])*(x1[2]-x3[2]))==0&&dist(x1[0],x1[1],x1[2],x3[0],x3[1],x3[2])==dist(x1[0],x1[1],x1[2],x4[0],x4[1],x4[2]))
        {
            x=x3[0]+x4[0]-x1[0];
            y=x3[1]+x4[1]-x1[1];
            z=x3[2]+x4[2]-x1[2];
            if(x==x2[0]&&y==x2[1]&&z==x2[2])
                flag=1;
        }
        cout<<"Case #"<<++Case<<":"<<" ";
        if(flag)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}
时间: 2024-08-06 16:06:46

HDU 5206的相关文章

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

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

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

HDU 6203 ping ping ping [LCA,贪心,DFS序,BIT(树状数组)]

题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=6203] 题意 :给出一棵树,如果(a,b)路径上有坏点,那么(a,b)之间不联通,给出一些不联通的点对,然后判断最少有多少个坏点. 题解 :求每个点对的LCA,然后根据LCA的深度排序.从LCA最深的点对开始,如果a或者b点已经有点被标记了,那么continue,否者标记(a,b)LCA的子树每个顶点加1. #include<Bits/stdc++.h> using namespace std;

HDU 5542 The Battle of Chibi dp+树状数组

题目:http://acm.hdu.edu.cn/showproblem.php?pid=5542 题意:给你n个数,求其中上升子序列长度为m的个数 可以考虑用dp[i][j]表示以a[i]结尾的长度为j的上升子序列有多少 裸的dp是o(n2m) 所以需要优化 我们可以发现dp的第3维是找比它小的数,那么就可以用树状数组来找 这样就可以降低复杂度 #include<iostream> #include<cstdio> #include<cstring> #include

hdu 1207 汉诺塔II (DP+递推)

汉诺塔II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4529    Accepted Submission(s): 2231 Problem Description 经典的汉诺塔问题经常作为一个递归的经典例题存在.可能有人并不知道汉诺塔问题的典故.汉诺塔来源于印度传说的一个故事,上帝创造世界时作了三根金刚石柱子,在一根柱子上从下往

[hdu 2102]bfs+注意INF

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 感觉这个题非常水,结果一直WA,最后发现居然是0x3f3f3f3f不够大导致的--把INF改成INF+INF就过了. #include<bits/stdc++.h> using namespace std; bool vis[2][15][15]; char s[2][15][15]; const int INF=0x3f3f3f3f; const int fx[]={0,0,1,-1};

HDU 3555 Bomb (数位DP)

数位dp,主要用来解决统计满足某类特殊关系或有某些特点的区间内的数的个数,它是按位来进行计数统计的,可以保存子状态,速度较快.数位dp做多了后,套路基本上都差不多,关键把要保存的状态给抽象出来,保存下来. 简介: 顾名思义,所谓的数位DP就是按照数字的个,十,百,千--位数进行的DP.数位DP的题目有着非常明显的性质: 询问[l,r]的区间内,有多少的数字满足某个性质 做法根据前缀和的思想,求出[0,l-1]和[0,r]中满足性质的数的个数,然后相减即可. 算法核心: 关于数位DP,貌似写法还是