[BC]Four Inages Strategy(三维空间判断正方形)
生活随笔
收集整理的這篇文章主要介紹了
[BC]Four Inages Strategy(三维空间判断正方形)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目連接 :http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=577&pid=1001
題目大意:在三維空間中,給你四個點,判斷是否可以組成一個正方形:
解題思路:首先判斷四條邊是否相等,判斷方法取三個邊如果兩邊相等且平方和相加等于第三邊平方和即可,在判斷是否有一個角為直角,判斷方法取三點叉乘為0就為直角。
AC代碼:
#include<iostream> #include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<algorithm> using namespace std; struct point {int x;int y;int z; }p[5]; int dis(point a,point 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); } int cheng(point a,point b,point c) {return (a.x-b.x)*(c.x-a.x)+(a.y-b.y)*(c.y-a.y)+(a.z-b.z)*(c.z-a.z); } int fun(int a,int b,int c) {if((a==b&&a+b==c)||(a==c&&a+c==b)||(c==b&&c+b==a)) return 1;else return 0; } int judge() {int a,b,c,a2,b2,c2,a3,b3,c3,t;a=dis(p[0],p[1]),b=dis(p[0],p[2]),c=dis(p[0],p[3]);a2=dis(p[1],p[0]),b2=dis(p[1],p[2]),c2=dis(p[1],p[3]);a3=dis(p[2],p[0]),b3=dis(p[2],p[1]),c3=dis(p[2],p[3]);if(fun(a,b,c)&&fun(a2,b2,c2)&&fun(a3,b3,c3)){int ab,bc,ac;ab=cheng(p[0],p[1],p[2]);bc=cheng(p[1],p[2],p[0]);ac=cheng(p[2],p[0],p[1]);if(ab==0||bc==0||ac==0) return 1;}return 0; } int main() {int i,k,tcase;scanf("%d",&tcase);for(k=1;k<=tcase;k++){for(i=0;i<4;i++) scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].z);printf("Case #%d: %s\n",k,(judge())?"Yes":"No");}return 0; }?
轉載于:https://www.cnblogs.com/gaojupeng/p/4438039.html
總結
以上是生活随笔為你收集整理的[BC]Four Inages Strategy(三维空间判断正方形)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [控件] TranformFadeVie
- 下一篇: FastDFS的配置、部署与API使用解