ccpc-1008-HDU5839Special Tetrahedron-计算几何

计算几何水题。暴力搞

注意力全部都在02那里,完全没想这道题!

  1 /*--------------------------------------------------------------------------------------*/
  2 
  3 #include <algorithm>
  4 #include <iostream>
  5 #include <cstring>
  6 #include <ctype.h>
  7 #include <cstdlib>
  8 #include <cstdio>
  9 #include <vector>
 10 #include <string>
 11 #include <queue>
 12 #include <stack>
 13 #include <cmath>
 14 #include <set>
 15 #include <unordered_set>
 16 #include <map>
 17 
 18 //debug function for a N*M array
 19 #define debug_map(N,M,G) printf("\n");for(int i=0;i<(N);i++)\
 20 {for(int j=0;j<(M);j++){\
 21 printf("%d",G[i][j]);}printf("\n");}
 22 //debug function for int,float,double,etc.
 23 #define debug_var(X) cout<<#X"="<<X<<endl;
 24 #define LL long long
 25 const int INF = 0x3f3f3f3f;
 26 const LL LLINF = 0x3f3f3f3f3f3f3f3f;
 27 const int prime = 2333;
 28 const int MOD = 1e9+7;
 29 
 30 /*--------------------------------------------------------------------------------------*/
 31 using namespace std;
 32 
 33 const int maxn = 210;
 34 int N,M,T;
 35 
 36 struct point{
 37     int x,y,z;
 38     point(int _x=0,int _y=0,int _z=0):x(_x),y(_y),z(_z){}
 39 
 40     bool operator < (const point &rhs) const
 41     {
 42         if(y == rhs.y && x == rhs.x) return z < rhs.z;
 43         else if(x == rhs.x) return y < rhs.y;
 44         else return x < rhs.x;
 45     }
 46     point operator + (const point B) const
 47     {
 48         return point(x+B.x,y+B.y,z+B.z);
 49     }
 50     point operator - (const point B) const
 51     {
 52         return point(x-B.x,y-B.y,z-B.z);
 53     }
 54     int operator * (const point B) const
 55     {
 56         return x*B.x + y*B.y + z*B.z;
 57     }
 58     point operator ^ (const point B) const
 59     {
 60         return point(y*B.z - z*B.y,
 61                      z*B.x - x*B.z,
 62                      x*B.y - y*B.x);
 63     }
 64 }pt[maxn];
 65 typedef point vec;
 66 
 67 struct node{
 68     int id;
 69     int dis;
 70     bool operator < (const node &rhs) const
 71     {
 72         return dis < rhs.dis;
 73     }
 74 };
 75 
 76 int dis(point a,point b)
 77 {
 78     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);
 79 }
 80 bool onPlane(point a,point b,point c,point d)
 81 {
 82     return ( ((a-c) ^ (a-d)) * (a-b) ) == 0 ;
 83 }
 84 int _onPlane(point a,point b,point c,point d)
 85 {
 86     return ( ((a-c) ^ (a-d)) * (a-b) ) ;
 87 }
 88 
 89 vector <node> ppt[maxn];
 90 unordered_set <int > st;
 91 
 92 int myHash(LL a,LL b,LL c,LL d)
 93 {
 94     return ((((a*prime%MOD + b)*prime%MOD +c)*prime%MOD +d) + MOD )%MOD;
 95 }
 96 
 97 int cas;
 98 int main()
 99 {
100     //freopen("input","r",stdin);
101     scanf("%d",&T);
102     while(T--)
103     {
104         scanf("%d",&N);
105         for(int i=0,x,y,z;i<N;i++)
106         {
107             scanf("%d%d%d",&x,&y,&z);
108             pt[i].x = x;
109             pt[i].y = y;
110             pt[i].z = z;
111         }
112 
113         st.clear();
114         for(int i=0;i<N;i++)
115         {
116             node tmp;
117             ppt[i].clear();
118             for(int j=0;j < N;j++) if(i != j)
119             {
120                 tmp.dis = dis(pt[i],pt[j]);
121                 tmp.id = j;
122                 ppt[i].push_back(tmp);
123             }
124             sort(ppt[i].begin(),ppt[i].end());
125         }
126 
127         int ans = 0;
128         int save[10];
129         for(int i=0;i<N;i++)
130         {
131             for(int j=i+1;j<N;j++)
132             {
133                 //printf("now use:%d %d\n",i,j);
134                 for(int k=0;k<ppt[i].size();k++) if(ppt[i][k].id != j)
135                 {
136                     for(int h=k+1;h<ppt[i].size() && ppt[i][k].dis == ppt[i][h].dis;h++) if(ppt[i][h].id != j)
137                     {
138                         if(dis(pt[j],pt[ppt[i][h].id]) == dis(pt[j],pt[ppt[i][k].id]) && dis(pt[j],pt[ppt[i][h].id]) == ppt[i][k].dis)
139                         {
140                             if(onPlane(pt[i],pt[j],pt[ppt[i][k].id],pt[ppt[i][h].id]) ) continue;
141                             //int s = myhash(i,j,ppt[i][k].id,ppt[i][h].id);
142                             //printf("%d %d %d %d\n",i,j,ppt[i][k].id,ppt[i][h].id);
143                             vector <int> ve;
144                             ve.push_back(i);
145                             ve.push_back(j);
146                             ve.push_back(ppt[i][k].id);
147                             ve.push_back(ppt[i][h].id);
148                             sort(ve.begin(),ve.end());
149                             int s = myHash(ve[0],ve[1],ve[2],ve[3]);
150                             if(st.find(s) == st.end())
151                             {
152                                 st.insert(s);
153                                 //printf("%d %d %d %d\n",i,j,ppt[i][k].id,ppt[i][h].id);
154                                 //printf("%d\n",_onPlane(pt[i],pt[j],pt[ppt[i][k].id],pt[ppt[i][h].id]));
155                                 ans++;
156                             }
157 
158                         }
159                     }
160                 }
161             }
162         }
163 
164         printf("Case #%d: %d\n",++cas,ans);
165     }
166 }

 

posted @ 2016-08-15 01:05  Helica  阅读(319)  评论(0编辑  收藏  举报