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
题意
求至少四边相等的四面体个数
题解
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