HDU 5206 Four Inages Strategy 水题

题目链接:

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
*/

 

转载于:https://www.cnblogs.com/fenice/p/5399576.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值