标签:
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 767 Accepted Submission(s): 201
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <queue> #include <map> #include <algorithm> #include <set> #define MM(a,b) memset(a,b,sizeof(a)) typedef long long ll; typedef unsigned long long ULL; const double eps = 1e-8; const int inf = 0x3f3f3f3f; const double pi=acos(-1); using namespace std; const int N=1e5+8; struct Point{ ll x,y,z,dis; int id; void read(){ scanf("%lld%lld%lld",&x,&y,&z); } bool operator<(const Point &a) const{ return this->dis<a.dis; } }p[205],v[205]; Point operator-(Point a,Point b) { return (Point){a.x-b.x,a.y-b.y,a.z-b.z}; } double dis(Point a) { return a.x*a.x+a.y*a.y+a.z*a.z; } Point cross(Point a,Point b) { return (Point){a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x}; } double area(Point a,Point b,Point c) { return dis(cross(b-a,c-a)); } double dot(Point a,Point b) { return a.x*b.x+a.y*b.y+a.z*b.z; } bool onface(Point a,Point b,Point c,Point d) { Point f=cross(a-b,c-b); return dot(f,d-b)==0; } int main() { int cas,n,kk=0,x,y; scanf("%d",&cas); while(cas--) { scanf("%d",&n); for(int i=1;i<=n;i++) p[i].read(); ll ans6=0,ans45=0; for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) { ll len=dis(p[i]-p[j]); int cnt=0; for(int k=1;k<=n;k++) if(k!=i&&k!=j) { if(dis(p[k]-p[i])-dis(p[k]-p[j])==0) { v[++cnt]=p[k]; v[cnt].dis=dis(p[k]-p[i]); } } for(int k=1;k<=cnt;k++) for(int w=k+1;w<=cnt;w++) { if((v[w].dis-v[k].dis)!=0) continue; if(onface(p[i],p[j],v[k],v[w])) continue; ll tmp=dis(v[w]-v[k]); if((tmp-len)==0&&(len-v[k].dis)==0) ans6++; else ans45++; } } ans45/=2;ans6/=6; printf("Case #%d: %lld\n",++kk,ans45+ans6); } return 0; }
分析:只想说两点:
1.两点连线的中垂线经过的整格点肯定是不多的,所以由此可以暴力。
2.T了话尝试去掉sqrt
标签:
原文地址:http://www.cnblogs.com/smilesundream/p/5778311.html