hdu 5839 Special Tetrahedron 计算几何 求特殊四面体个数

Special Tetrahedron

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

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,1≤T≤20, the number of test cases.

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

The next n lines contains three integers xi,yi,zi, (−2000≤xi,yi,zi≤2000), 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

Author

UESTC

Source

2016中国大学生程序设计竞赛 - 网络选拔赛

题意

求至少四边相等的四面体个数

题解

n^3枚举与两点中点共面且与线垂直的点数m

m^2判断是否符合

最后删除重复的

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
struct point
{
    double x,y,z;
}a[203];
int n,T,ans,ans2,tot,tmp[203];
double d[203][203];
double qdis(int i,int j)
{
    return sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y)+(a[i].z-a[j].z)*(a[i].z-a[j].z));
}
point operator -(point A,point B)
{
    point C;
    C.x=A.x-B.x;
    C.y=A.y-B.y;
    C.z=A.z-B.z;
    return C;
}
point operator +(point A,point B)
{
    point C;
    C.x=A.x+B.x;
    C.y=A.y+B.y;
    C.z=A.z+B.z;
    return C;
}
point operator /(point A,double B)
{
    point C;
    C.x=A.x/B;
    C.y=A.y/B;
    C.z=A.z/B;
    return C;
}
double operator *(point A,point B)
{
    return A.x*B.x+A.y*B.y+A.z*B.z;
}
bool check(point A,point B)
{
    if(abs(A*B)<0.00000001)return true;
    else return false;
}
bool check2(point A,point B)
{
    if(abs(A.x-B.x)<0.00000001&&abs(A.y-B.y)<0.000000001&&abs(A.z-B.z)<0.000000001)
    return false;
    return true;
}
bool check3(int i,int j,int k,int l)
{
    if(d[i][j]==d[l][k]&&d[i][l]==d[i][j])
    return true;
    return false;
}
int main()
{
    cin>>T;
    for(int p=1;p<=T;p++)
    {
        ans2=ans=0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%lf%lf%lf",&a[i].x,&a[i].y,&a[i].z);
        }
        for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
            d[i][j]=qdis(i,j);
        }
        /*for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            cout<<d[i][j]<<" ";
            cout<<endl;
        }*/
        for(int i=2;i<=n;i++)
        {
            for(int j=1;j<i;j++)
            {
                tot=0;
                for(int k=1;k<=n;k++)
                {
                    if(k!=i&&k!=j)
                    {
                        if(check((a[i]+a[j])/2-a[k],a[i]-a[j]))
                        {
                            tmp[++tot]=k;
                        }
                    }
                }
                //cout<<tot<<": ";
                ///for(int k=1;k<=tot;k++)
                //cout<<tmp[k]<<" ";cout<<endl;
                for(int k=2;k<=tot;k++)
                for(int l=1;l<k;l++)
                {
                    if(abs(d[tmp[k]][i]-d[tmp[l]][i])<0.000001)
                    {
                        if(check2((a[tmp[k]]+a[tmp[l]])/2,(a[i]+a[j])/2))
                        {
                            ans++;
                            if(check3(tmp[k],tmp[l],i,j))
                            ans2++;
                        }
                    }
                }
            }
        }
        ans=ans-(ans2/6)*4;
        cout<<"Case #"<<p<<": "<<ans/2<<endl;
    }
    return 0;
}

m

时间: 2024-10-07 00:16:26

hdu 5839 Special Tetrahedron 计算几何 求特殊四面体个数的相关文章

HDU 5839 Special Tetrahedron(计算几何)

传送门 Special Tetrahedron Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 616    Accepted Submission(s): 258 Problem Description Given n points which are in three-dimensional space(without repetit

HDU 5839 Special Tetrahedron (2016CCPC网络赛08) (暴力+剪枝)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5839 在一个三维坐标,给你n个点,问你有多少个四面体(4个点,6条边) 且满足至少四边相等 其余两边不相邻. 暴力4重循环,但是在第3重循环的时候需要判断是否是等腰三角形,这便是一个剪枝.在第4重循环的时候判断4点是否共面 (叉乘), 5或者6边相等就+1,4边相等就判断另外两边是否相交就行了. 赛后过的,觉得自己还是太菜了. 1 //#pragma comment(linker, "/STACK:

HDU 5839 Special Tetrahedron

暴力水过,数据水. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue>

5839Special Tetrahedron---hdu5839(计算几何,求特殊四面体个数)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5839 给你n个三维的点,然后求这n各点可以构成多少个特殊四面体,特殊四面体满足一下两点: 1.至少有四条面相等: 2.如果只有四条边相等,那么剩下的两条边不相邻: n的范围是300: 暴力枚举四面体的其中一条边的两点,然后让另外两点到这两点的距离相等,判断一下这四个点是否共面: 还有如果能构成四面体看一下是否是正四面体,如果是正四面体,则六条边都会能枚举一边,结果的一部分是正六面体的个数/6:否则则

hdu-5839 Special Tetrahedron(计算几何)

题目链接: Special Tetrahedron Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Problem Description Given n points which are in three-dimensional space(without repetition). Please find out how many distinct Special Tetr

hdu 6069 Counting Divisors(求因子的个数)

Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 3170    Accepted Submission(s): 1184 Problem Description In mathematics, the function d(n) denotes the number of divisors of

HDU 3395 Special Fish 最“大”费用最大流

求最大费用可以将边权取负以转化成求最小费用.然而此时依然不对,因为会优先寻找最大流,但是答案并不一定出现在满流的时候.所以要加一些边(下图中的红边)使其在答案出现时满流.设所有边的流量为1,花费如下图所示.显然最大花费是1001,而没有红边的情况下会得到3. #include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio>

HDU 4569 Special equations(数学推论)

题目 //想不出来,看了解题报告 /* 题意:给你一个最高幂为4的一元多项式,让你求出一个x使其结果模p*p为0. 题解:f(x)%(p*p)=0那么一定有f(x)%p=0,f(x)%p=0那么一定有f(x+p)%p=0. 所以我们可以开始从0到p枚举x,当f(x)%p=0,然后再从x到p*p枚举,不过每次都是+p,找到了输出即可,没有的话No solution! */ #include<stdio.h> int main() { int t,n; __int64 a[5],p; scanf(

Board Wrapping(计算几何求凸包加向量的旋转)

UVA - 10652 Board Wrapping Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [Submit]   [Go Back]   [Status] Description Problem B Board Wrapping Input: standard input Output: standard output Time Limit: 2 seconds The small sa