HDU-5839 Special Tetrahedron(纯暴力)
来源:互联网 发布:自动加粉软件 编辑:程序博客网 时间:2024/06/05 15:49
Special Tetrahedron
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 395 Accepted Submission(s): 162
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.
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 integerT,1≤T≤20 , the number of test cases.
Each case begins with an integern(n≤200) , indicating the number of the points.
The nextn lines contains three integers xi,yi,zi ,(−2000≤xi,yi,zi≤2000) , representing the coordinates of the ith point.
The first line is an integer
Each case begins with an integer
The next
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
240 0 00 1 11 0 11 1 090 0 00 0 21 1 1-1 -1 11 -1 1-1 1 11 1 01 0 10 1 1
Sample Output
Case #1: 1Case #2: 6
题意:在空间中的点里面找到有多少点可以组成满足下列条件的四面体:
1.至少有四条边相同.
2.在确保4条边相等的情况下,另外的两条边不相邻。
QAQ,昨天4道题止步于网络赛,奈何这个第五道三维几何没做过,被吓住了 TAT ..根本没有1003难嘛。。
题解:枚举对角线,找到所有和对角线两端点相等的点,然后去枚举所有的和对角线距离相等的点(还要判断四点不共面)。因为有两条对角线,所以答案会被算两次。然后是正四面体,我们每条线都被多算了1次,总共算了6次,我们只要其中的一次。所以最终答案为 (ans1/6+ans2/2)交代码请用G++。。
n^4暴力,但实际上复杂度达不到n^4【和出题人是否懒惰有关,233
暴力枚举两个点,然后再枚举离这两点距离相同的点。
再枚举四个点,找到这个四边形四边相同,但是不共面的四个点。
再判断这个是不是正四边形,如果是正四边形的话,你会重复计算6次
否则重复计算两次。
代码如下:
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<limits.h>#include<queue>#include<math.h>#include<stack>#include<vector>#include<algorithm>using namespace std;#define maxn 205struct node{int x;int y;int z;}a[maxn];long long dis(node a,node b);int sq(int a);bool check(node a,node b,node c,node d);bool check(node a,node b,node c,node d){ node 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 1;//如果三个方向向量组成的行列式为0,则四点共面 return 0;}int sq(int a){return a*a;}long long dis(node a,node b){return sq(a.x-b.x)+sq(a.y-b.y)+sq(a.z-b.z);}int s[maxn];int main(){int T,n,m,i,j,k,h,ans,cases=0;long long ans1,ans2;scanf("%d",&T);while(T--){memset(s,0,sizeof(s));memset(a,0,sizeof(a));ans1=0;ans2=0;scanf("%d",&n);for(i=1;i<=n;i++) scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);for(i=1;i<=n;i++){for(j=1+i;j<=n;j++){int cnt=0;for(k=1;k<=n;k++){if(k==i || k==j) continue;if(dis(a[i],a[k])==dis(a[j],a[k])) s[cnt++]=k;}if(cnt<=1) continue;else for(h=0;h<cnt;h++) { for(int h1=h+1;h1<cnt;h1++) { int id1=s[h],id2=s[h1]; if(dis(a[id1],a[i])!=dis(a[id2],a[i]))//相邻的两条边要相等 continue; if(check(a[i],a[j],a[id1],a[id2]))//判断四点是否共面 continue; if(dis(a[id1],a[id2])==dis(a[i],a[j]) && dis(a[id1],a[i])==dis(a[i],a[j])) ans1++; else ans2++; } }}}printf("Case #%d: %d\n",++cases,ans1/6+ans2/2);}}
0 0
- HDU-5839 Special Tetrahedron(纯暴力)
- HDU 5839 Special Tetrahedron(几何+暴力)
- hdu 5839 Special Tetrahedron
- HDU 5839 Special Tetrahedron
- HDU 5839 Special Tetrahedron
- HDU 5839 Special Tetrahedron
- HDU 5839 Special Tetrahedron(计算几何)
- 2016CCPC网预 HDU 5839 Special Tetrahedron
- hdu 5839 Special Tetrahedron (判断四面体)
- HDU 5839 Special Tetrahedron(计算几何)
- HDU 5839 Special Tetrahedron(计算几何)
- 2016中国大学生程序设计竞赛 - 网络选拔赛 hdu 5839 Special Tetrahedron
- HDU 5839 Special Tetrahedron (三维计算几何)
- 【2016-CCPC-H】计算几何(Special Tetrahedron,hdu 5839)
- HDU 5839 Special Tetrahedron(计算几何)——2016中国大学生程序设计竞赛 - 网络选拔赛
- hdoj 5839 Special Tetrahedron 叉积点积判断四点共面模板
- HDU 4151The Special Number(暴力+二分)
- hdu 4569 Special equations ( 必要条件缩小范围后暴力)
- C++内存分配
- 数据库的创建以及对数据库的增删改查
- VC中的注册表操作(VC_Win32)
- POJ 3083 Children of the Candy Corn(DFS+BFS)
- 单词2016.8.15
- HDU-5839 Special Tetrahedron(纯暴力)
- mysql+powerdesigner
- 学习一下linux中的进程,文件查找,文件压缩与IO重定向
- select 连接
- service中创建浮窗
- 浅谈2016关于用户体验网站优化中的重要性!
- kafka集群环境搭建
- 字符串匹配之KMP、BoyerMoore、Sunday算法
- 浅谈Java多线程(volatile实现可见性)