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

题意:

问最少有四条边相同的四面体有多少个?

思路:

枚举一条边的两点,在枚举另外两点,在枚举第3个点的时候要判断是否是等腰三角形和三点是否共线,在枚举第4个点的时候要判断与前边两点是否是等腰三角形和是否共线(共线可以留在判断是否共面一块判断),还要判断这两个等腰三角形腰长是否相等;最后来到至少有4条边相等的四面体,如果它是正四面体就被重复算了6次,否则被重复算了两次;所有答案就出来了;

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
//#include <bits/stdc++.h>
#include <stack>
#include <map>

using namespace std;

#define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss));

typedef  long long LL;

template<class T> void read(T&num) {
    char CH; bool F=false;
    for(CH=getchar();CH<‘0‘||CH>‘9‘;F= CH==‘-‘,CH=getchar());
    for(num=0;CH>=‘0‘&&CH<=‘9‘;num=num*10+CH-‘0‘,CH=getchar());
    F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
    if(!p) { puts("0"); return; }
    while(p) stk[++ tp] = p%10, p/=10;
    while(tp) putchar(stk[tp--] + ‘0‘);
    putchar(‘\n‘);
}

const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+10;
const int maxn=210;
const double eps=1e-12;

int n;
struct PO
{
    int x,y,z;
}po[maxn];

int check1(PO a,PO b,PO c)//判断共线;
{
    PO temp1,temp2;
    temp1.x=a.x-b.x;temp1.y=a.y-b.y;temp1.z=a.z-b.z;
    temp2.x=c.x-b.x;temp2.y=c.y-b.y;temp2.z=c.z-b.z;
    if(temp1.x*temp2.y==temp1.y*temp2.x&&temp1.x*temp2.z==temp1.z*temp2.x&&temp1.y*temp2.z==temp1.z*temp2.y)return 1;
    return 0;
}
int check2(PO a,PO b,PO c,PO d)//判断共面;
{
    int x1=b.x-a.x,y1=b.y-a.y,z1=b.z-a.z;
    int x2=c.x-a.x,y2=c.y-a.y,z2=c.z-a.z;
    int x3=d.x-a.x,y3=d.y-a.y,z3=d.z-a.z;
    LL t1=(LL)x1*y2*z3+y1*z2*x3+z1*x2*y3;
    LL t2=(LL)z1*x3*y2+x2*y1*z3+x1*z2*y3;
    if(t1==t2)return 1;
    return 0;
}
int dis(PO a,PO b)
{
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z);
}
int solve()
{
    int sum1=0,sum2=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                if(k==i||k==j)continue;
                int dist=dis(po[k],po[i]);
                if(dist!=dis(po[k],po[j]))continue;
                if(check1(po[i],po[j],po[k]))continue;
                for(int u=k+1;u<=n;u++)
                {
                    if(u==i||u==j)continue;
                    if(dis(po[u],po[i])!=dis(po[u],po[j]))continue;
                    if(dis(po[u],po[i])!=dist)continue;
                   //if(i==1&&j==2&&k==3)cout<<check2(po[k],po[u],po[i],po[j])<<u<<"&%&^^*(\n";
                    if(check2(po[u],po[k],po[i],po[j]))continue;
                    if(dis(po[u],po[k])==dist&&dis(po[i],po[j])==dist)sum2++;
                    else sum1++;
                }
            }
        }
    }
    return sum1/2+sum2/6;
}

int main()
{
    int t,Case=0;
    read(t);
    while(t--)
    {
        read(n);
        For(i,1,n)
        {
            read(po[i].x);read(po[i].y);read(po[i].z);
        }
        printf("Case #%d: %d\n",++Case,solve());
    }
    return 0;
}

  

时间: 2024-10-06 11:51:47

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): 175    Accepted Submission(s): 64 Problem Description Given n points which are in three-dimensional space(without repetition).

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>

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(

【HDU 5839】Special Tetrahedron(计算几何)

空间的200个点,求出至少四边相等,且其余两边必须不相邻的四面体的个数. 用map记录距离点i为d的点有几个,这样来优化暴力的四重循环. 别人的做法是枚举两点的中垂面上的点,再把到中点距离相等的点找出来,n^3的样子. 还要注意四个点共面的情况. 共面判断就是用叉乘计算出ijk三点所在面的法向量,然后判断il向量是否和法向量垂直,是则共面. #include <cstdio> #include <cstring> #include <algorithm> #includ

HDU 4063 Aircraft(计算几何)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4063 Description You are playing a flying game. In the game, player controls an aircraft in a 2D-space. The mission is to drive the craft from starting point to terminal point. The craft needs wireless s

HDU 4569 Special equations(取模)

Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4569 Description Let f(x) = a nx n +...+ a 1x +a 0, in which a i (0 <= i <= n) are all known integers. We call f(x) 0 (mod