题目链接:
hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5206
bc(中文):http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=577&pid=1001
题解:
先判四点是否共面,然后再判断一下四条邻边相等并且两条对角线相等就可以了。
#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int maxn=1000+10; typedef long long LL; struct Point { LL x,y,z; Point(LL x,LL y,LL z):x(x),y(y),z(z){} Point(){}; friend Point operator - (const Point& p1,const Point& p2){ return Point(p1.x-p2.x,p1.y-p2.y,p1.z-p2.z); } } pt[4]; typedef Point Vector; Vector cross(const Vector& v1,const Vector& v2){ return Vector(v1.y*v2.z-v1.z*v2.y,v2.x*v1.z-v1.x*v2.z,v1.x*v2.y-v1.y*v2.x); } LL dis(int i,int j) { Point pt1=pt[i]; Point pt2=pt[j]; return (pt1.x-pt2.x)*(pt1.x-pt2.x)+(pt1.y-pt2.y)*(pt1.y-pt2.y)+(pt1.z-pt2.z)*(pt1.z-pt2.z); } bool judge(){ Vector v1=pt[1]-pt[0]; Vector v2=pt[2]-pt[0]; Vector v3=pt[3]-pt[0]; Vector cr1=cross(v1,v2); Vector cr2=cross(v2,v3); Vector ret=cross(cr1,cr2); if(!ret.x&&!ret.y&&!ret.z) return true; return false; } int main() { int tc,kase=0; scanf("%d",&tc); while(tc--) { for(int i=0; i<4; i++) scanf("%lld%lld%lld",&pt[i].x,&pt[i].y,&pt[i].z); int flag=0; if(judge()) { for(int i=0; i<4; i++) { for(int j=0; j<4; j++) { if(j!=i) { for(int k=0; k<4; k++) { if(k!=j&&k!=i) { for(int l=0; l<4; l++) { if(l!=i&&l!=j&&l!=k) { if(dis(i,j)==dis(j,k)&&dis(j,k)==dis(k,l)&&dis(k,l)==dis(l,i)&&dis(i,k)==dis(j,l)) { flag=1; } } } } } } } } } printf("Case #%d: ",++kase); if(flag) { puts("Yes"); } else { puts("No"); } } return 0; } /* 1 0 0 0 1 0 0 -1 0 0 0 1 1 0 0 0 1 0 0 -1 0 -1 0 0 */