hdu5839Special Tetrahedron+几何计算
2016-08-15 21:46
351 查看
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.
At least four edges have the same length.
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个点。取多少个4个点可以组成一个特殊的4面体。特殊4面体至少4条边不等,如果恰好4条边相等,另外两条不相等的边不相邻。
//暴力n^4的枚举4个点作为对边,只要这除了这两个对边的边相等的话就满足题目要求,就算对边不相等,他也是的不相邻的。。所以直接暴力。注意判断4点共面的情况。以及去重。
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.
At least four edges have the same length.
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个点。取多少个4个点可以组成一个特殊的4面体。特殊4面体至少4条边不等,如果恰好4条边相等,另外两条不相等的边不相邻。
//暴力n^4的枚举4个点作为对边,只要这除了这两个对边的边相等的话就满足题目要求,就算对边不相等,他也是的不相邻的。。所以直接暴力。注意判断4点共面的情况。以及去重。
#include<bits/stdc++.h> using namespace std; const double eps=1e-8; struct point3{ int x,y,z; point3(){}; point3(int x,int y,int z):x(x),y(y),z(z){}; bool operator < (const point3 &a)const{ if(x!=a.x) return x<a.x; if(y!=a.y) return y<a.y; return z<a.z; } point3 operator + (const point3 &a)const{ return point3(x+a.x,y+a.y,z+a.z); } bool operator == (const point3 &a) const{ return (x==a.x&&y==a.y&&z==a.z); } }p[205]; int dis2(const point3 &a,const point3 &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); } struct point4{ point3 a[5]; void ss(){ sort(a,a+4); } }; bool operator<(const point4 &x,const point4 &y){ for(int i = 0;i < 4;++i){ if(x.a[i] < y.a[i]){ return true; } else if(y.a[i] < x.a[i]){ return false; } } return false; } set<point4>Q; //去重 set<point4>::iterator it; int main(){ int t; scanf("%d",&t); for(int cas=1;cas<=t;cas++){ int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d %d %d",&p[i].x,&p[i].y,&p[i].z); int ans=0; Q.clear(); for(int i=0;i<n;i++){ for(int j=i+1 ;j<n;j++){ for(int k=0;k<n;k++){ if(k==i||k==j) continue; int d1=dis2(p[i],p[k]); int d2=dis2(p[j],p[k]); if(d1!=d2) continue; for(int l=k+1;l<n;l++){ int d3=dis2(p[i],p[l]); int d4=dis2(p[j],p[l]); if(d3!=d4) continue; if(d1!=d4) continue; if(p[i]+p[j]==p[k]+p[l]) continue; //4点共面 point4 dd; dd.a[0]=p[i]; dd.a[1]=p[j]; dd.a[2]=p[k]; dd.a[3]=p[l]; dd.ss(); if(Q.find(dd)==Q.end()){ Q.insert(dd); ans++; } }//l }//k }//j }//i printf("Case #%d: %d\n",cas,ans); } return 0; }
相关文章推荐
- 初学算法 - 求凸包的Garham's Scan算法的C++实现
- 【Google Code Jam 2009 round2 problem D】Watering Plants (两圆交点求法详解)
- 计算几何模板
- 计算几何小模板
- BZOJ2829信用卡凸包
- Farthest Point
- HDU 4922 Hello, Your Package! (计算几何+DP)(WA)
- poj 1514&zoj 1185 Metal Cutting(半平面交)
- UVA 10969 Sweet Dream(圆的相交)
- uva 11177 Fighting Against a Polygonal Monster(凸包与圆的面积交)
- POJ1279 && LA2512 Art Gallery(求多边形的核)
- poj 2540 && uva 10084 Hotter Colder(半平面交)
- UVALive 5878 - Shortest Leash 【计算几何】
- 【计算几何】POJ 2318 & POJ 2398
- 【计算几何】POJ 2653
- 【计算几何】POJ 1113
- HDU 5128 The E-pang Palace
- POJ 2318 TOYS(叉积+二分or暴力)
- POJ 2398 Toy Storage(叉积+二分)
- POJ 1228 Grandpa's Estate 计算凸包+判断点在线段上