Special Tetrahedron

题目连接:

http://acm.hdu.edu.cn/showproblem.php?pid=5839

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

Hint

题意

给你三维一些点,问你有多少个四边形满足以下条件

1.至少四个边相同

2.如果四个边相同,那么不相同的两个边不在一起。

题解:

n4暴力,但实际上复杂度达不到n4【和出题人是否懒惰有关,233

暴力枚举两个点,然后再枚举离这两点距离相同的点。

再枚举四个点,找到这个四边形四边相同,但是不共面的四个点。

再判断这个是不是正四边形,如果是正四边形的话,你会重复计算6次

否则重复计算两次。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 205;
struct point
{
int x,y,z;
point(){}
point(int x_,int y_,int z_):x(x_),y(y_),z(z_) {}
}p[210];
long long sq(long long a){
return a*a;
}
long long dis(point a,point b){
return sq(a.x-b.x)+sq(a.y-b.y)+sq(a.z-b.z);
}
bool check(point a,point b,point c,point d)
{
point s1,s2,s3;
s1.x=b.x-a.x;s1.y=b.y-a.y;s1.z=b.z-a.z;
s2.x=c.x-a.x;s2.y=c.y-a.y;s2.z=c.z-a.z;
s3.x=d.x-a.x;s3.y=d.y-a.y;s3.z=d.z-a.z;
long long ans=s1.x*s2.y*s3.z+s1.y*s2.z*s3.x+s1.z*s2.x*s3.y-s1.z*s2.y*s3.x-s1.x*s2.z*s3.y-s1.y*s2.x*s3.z;
if(ans==0)return true;
return false;
}
int Q[300],cas;
void solve(){
int n;scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].z);
}
long long ans1=0,ans2=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(k==i||k==j)continue;
if(dis(p[i],p[k])==dis(p[j],p[k]))
Q[cnt++]=k;
}
if(cnt<=1)continue;
for(int i1=0;i1<cnt;i1++)
{
for(int j1=i1+1;j1<cnt;j1++)
{
int id1=Q[i1],id2=Q[j1];
if(dis(p[id1],p[i])!=dis(p[id2],p[i]))continue;
if(check(p[i],p[j],p[id1],p[id2]))continue;
if(dis(p[i],p[j])==dis(p[id1],p[i])&&dis(p[i],p[j])==dis(p[id1],p[id2]))ans2++;
else ans1++;
}
}
}
}
printf("Case #%d: %d\n",++cas,ans1/2+ans2/6);
}
int main(){
int t;
scanf("%d",&t);
while(t--)solve();
return 0;
}

HDU 5839 Special Tetrahedron 计算几何的更多相关文章

  1. HDU 5839 Special Tetrahedron

    HDU 5839 Special Tetrahedron 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n ...

  2. HDU 5839 Special Tetrahedron (计算几何)

    Special Tetrahedron 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n points ...

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5839 在一个三维坐标,给你n个点,问你有多少个四面体(4个点,6条边) 且满足至少四边相等 其余两边不 ...

  4. HDU 5130 Signal Interference(计算几何 + 模板)

    HDU 5130 Signal Interference(计算几何 + 模板) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5130 Descripti ...

  5. (四面体)CCPC网络赛 HDU5839 Special Tetrahedron

    CCPC网络赛 HDU5839 Special Tetrahedron 题意:n个点,选四个出来组成四面体,要符合四面体至少四条边相等,若四条边相等则剩下两条边不相邻,求个数 思路:枚举四面体上一条线 ...

  6. hdu 5839(三维几何)

    Special Tetrahedron Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

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

    空间的200个点,求出至少四边相等,且其余两边必须不相邻的四面体的个数. 用map记录距离点i为d的点有几个,这样来优化暴力的四重循环. 别人的做法是枚举两点的中垂面上的点,再把到中点距离相等的点找出 ...

  8. HDU 5979 Convex【计算几何】 (2016ACM/ICPC亚洲区大连站)

    Convex Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  9. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. iOS 提交应用过程出现的错误及#解决方案#images can't contain alpha channels or transparencies

        本文永久地址为http://www.cnblogs.com/ChenYilong/p/3977542.html ,转载请注明出处.    当你试图通过<预览>"导出&qu ...

  2. MySQL-数据操作-增删改查

    1.增加: insert into 表 (列名,列名...) values (值,值,值...) insert into 表 (列名,列名...) values (值,值,值...),(值,值,值.. ...

  3. 基于theano的多层感知机的实现

    1.引言 一个多层感知机(Multi-Layer Perceptron,MLP)可以看做是,在逻辑回归分类器的中间加了非线性转换的隐层,这种转换把数据映射到一个线性可分的空间.一个单隐层的MLP就可以 ...

  4. Nuts & Bolts Problem

    Given a set of n nuts of different sizes and n bolts of different sizes. There is a one-one mapping ...

  5. Ubuntu 12.04将默认集成Landscape管理套件【转】

    转自:https://imtx.me/archives/1702.html 今天,我像往常一样对我的Ubuntu 12.04 Beta进行了一次常规升级,然后我发现在系统设置当中多了一个图标,叫「Ma ...

  6. Java类的继承与多态特性-入门笔记

    相信对于继承和多态的概念性我就不在怎么解释啦!不管你是.Net还是Java面向对象编程都是比不缺少一堂课~~Net如此Java亦也有同样的思想成分包含其中. 继承,多态,封装是Java面向对象的3大特 ...

  7. Java 基本语法---Java运算符

    Java 基本语法---Java运算符 0. 概述 Java中的运算符主要分为以下几种: 算术运算符 赋值运算符 关系运算符 逻辑运算符 条件运算符 位运算符 其他运算符 1. 算术运算符 操作符 描 ...

  8. 交换机NTP的MD5配置

    1.ntp-service authentication enable  开启NTP身份验证功能 2.ntp-service source-interfer LoopBack0 指定本机发生NTP的端 ...

  9. Heist

    CF#509 div2 A 第一次用自己的号打CF祭. 题目描述 昨晚有一家电子商店被抢劫了. 昨天在商店里的所有键盘都是从x开始按升序编号的.例如,如果x=4,并且商店中有3个键盘,那么编号就为4, ...

  10. CSU 1948: 超级管理员(普通费用流&&zkw费用流)

    Description 长者对小明施加了膜法,使得小明每天起床就像马丁的早晨一样. 今天小明早上醒来发现自己成了一位仓管员.仓库可以被描述为一个n × m的网格,在每个网格上有几个箱子(可能没有).为 ...