zoukankan      html  css  js  c++  java
  • hdu 5839(三维几何)

    Special Tetrahedron

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 328    Accepted Submission(s): 130


    Problem Description
    Given n points which are in three-dimensional space(without repetition).

    Please find out how many distinct Special Tetrahedron among them. A tetrahedron is called Special Tetrahedron if it has two following characters.

    1. At least four edges have the same length.

    2. If it has exactly four edges of the same length, the other two edges are not adjacent.
     
    Input
    Intput contains multiple test cases.

    The first line is an integer T,1T20, the number of test cases.

    Each case begins with an integer n(n200), indicating the number of the points.

    The next n lines contains three integers xi,yi,zi, (2000xi,yi,zi2000), representing the coordinates of the ith point.
     
    Output
    For each test case,output a line which contains"Case #x: y",x represents the xth test(starting from one),y is the number of Special Tetrahedron.
     
    Sample Input
    2 4 0 0 0 0 1 1 1 0 1 1 1 0 9 0 0 0 0 0 2 1 1 1 -1 -1 1 1 -1 1 -1 1 1 1 1 0 1 0 1 0 1 1
     
    Sample Output
    Case #1: 1 Case #2: 6
     
    题意:在空间中的点里面找到有多少点可以组成满足下列条件的四面体:
    1.至少有四条边相同.
    2.在确保4条边相等的情况下,另外的两条边不相邻。
    QAQ,昨天4道题止步于网络赛,奈何这个第五道三维几何没做过,被吓住了 TAT ..根本没有1003难嘛。。
    题解:枚举对角线,找到所有和对角线两端点相等的点,然后去枚举所有的和对角线距离相等的点(还要判断四点不共面)。因为有两条对角线,所以答案会被算两次。然后是正四面体,我们每条线都被多算了1次,总共算了6次,我们只要其中的一次。所以最终答案为 (ans-same)/2+same/6 = ans/2- same/3...交代码请用G++。。
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <map>
    #define sqr(x) ((x)*(x))
    using namespace std;
    const double eps = 1e-8;
    struct Point
    {
        double x,y,z;
        Point(double x, double y, double z) : x(x), y(y), z(z) {}
        Point() {}
        Point operator - (const Point & p) const
        {
            return Point(x-p.x, y-p.y, z-p.z);
        }
    } p[250];
    struct Node
    {
        int idx;
        double dis;
    }node[250];
    int sig(double d)
    {
        return (d>eps) - (d<-eps);
    }
    //叉乘
    Point cross(const Point & a, const Point & b)
    {
        return Point(a.y*b.z-a.z*b.y, a.z*b.x-a.x*b.z, a.x*b.y-a.y*b.x);
    }
    Point cross(const Point & o, const Point & a, const Point & b)
    {
        return cross(a-o,b-o);
    }
    //点乘
    double dot(const Point & a, const Point & b)
    {
        return a.x*b.x + a.y*b.y + a.z*b.z;
    }
    //判断四点共面
    bool sameFace(const Point & a, const Point & b, const Point & c, const Point & d)
    {
        return sig(dot(b-a, cross(a, c, d))) == 0;
    }
    //两点距离
    double dis(const Point & a, const Point & b)
    {
        return sqrt(sqr(a.x-b.x) + sqr(a.y-b.y) + sqr(a.z-b.z));
    }
    int main()
    {
        int tcase,n,t=1;
        scanf("%d",&tcase);
        while(tcase--)
        {
            scanf("%d",&n);
            for(int i=1; i<=n; i++)
            {
                scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z);
            }
            int ans = 0,ans1=0;
            for(int i=1; i<=n; i++)
            {
                for(int j=i+1; j<=n; j++) ///枚举对角线
                {
                    int cnt = 0;
                    for(int k=1; k<=n; k++)
                    {
                        if(sig(dis(p[i],p[k])-dis(p[j],p[k]))==0)
                        {
                            node[++cnt].idx = k;
                            node[cnt].dis = dis(p[i],p[k]);
                        }
                    }
                    for(int k=1; k<=cnt; k++)
                    {
                        for(int l=k+1; l<=cnt; l++)
                        {
                            if(sig(node[k].dis-node[l].dis)!=0) continue;
                            if(sameFace(p[i],p[j],p[node[k].idx],p[node[l].idx])) continue;
                            ans++;
                            if(sig(dis(p[node[k].idx],p[node[l].idx])-node[k].dis)==0&&sig(dis(p[i],p[j])-node[k].dis)==0)
                            {
                                ans1++;
                            }
                        }
                    }
                }
            }
            printf("Case #%d: %d
    ",t++,ans/2-ans1/3);
        }
    }
     
  • 相关阅读:
    2017.9.29 ubuntu安装mysql服务
    如何在树莓派上安装mjpeg-streamer(针对摄像头为UVC的)
    2016.9.22感想及收获
    GL-iNET路由器如何安装DDNS服务
    2016.7.5 记项目过程中犯的一个从未察觉的低级错误
    C++课程笔记 Lesson 01
    关于Jlink在linux系统下连接错误的解决方法
    如何通过命令提示符进入MySQL服务器
    java面试题
    hive面试题
  • 原文地址:https://www.cnblogs.com/liyinggang/p/5772161.html
Copyright © 2011-2022 走看看