51nod 四点共面(数学)

1265 四点共面
基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏  关注
给出三维空间上的四个点(点与点的位置均不相同),判断这4个点是否在同一个平面内(4点共线也算共面)。如果共面,输出"Yes",否则输出"No"。
Input
第1行:一个数T,表示输入的测试数量(1 <= T <= 1000)
第2 - 4T + 1行:每行4行表示一组数据,每行3个数,x, y, z, 表示该点的位置坐标(-1000 <= x, y, z <= 1000)。
Output
输出共T行,如果共面输出"Yes",否则输出"No"。
Input示例
1
1 2 0
2 3 0
4 0 0
0 0 0
Output示例
Yes
借用:三个向量的混合积可以用行列式计算,而三个向量的混合积表示的是以这三个向量为三个相邻棱的平行六面体的体积。故为零即表示四点共面。
三个向量的混合积(叉乘)
A点乘(B叉乘C)为0则表示四点共面
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<ctime>
#include<string>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#include<set>
#include<map>
#include<cstdio>
#include<limits.h>
#define MOD 1000000007
#define fir first
#define sec second
#define fin freopen("/home/ostreambaba/文档/input.txt", "r", stdin)
#define fout freopen("/home/ostreambaba/文档/output.txt", "w", stdout)
#define mes(x, m) memset(x, m, sizeof(x))
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define INF 1e9+7
#define inf 0x3f3f3f3f
#define Pi 4.0*atan(1.0)

#define lowbit(x) (x&(-x))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-9;
const int mod = 1000000000+7;
const int maxn = 10000+10;
using namespace std;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}

struct point{
    double x,y,z;
    point operator-(const point &o){
        point ans;
        ans.x=this->x-o.x;
        ans.y=this->y-o.y;
        ans.z=this->z-o.z;
        return ans;
    }
}p[4];
double pointMuti(point p1,point p2){
    return (p1.x*p2.x)+(p1.y*p2.y)+(p1.z*p2.z);
}
point cross(point p1,point p2){
    point ans;
    ans.x=1.0*(p1.y*p2.z-p1.z*p2.y);
    ans.y=-1.0*(p1.x*p2.z-p1.z*p2.x);
    ans.z=1.0*(p1.x*p2.y-p1.y*p2.x);
    return ans;
}
int main(){
    //freopen("/home/ostreambaba/文档/input.txt", "r", stdin);
    //freopen("/home/ostreambaba/文档/output.txt", "w", stdout);
    int Case=read();
    while(Case--){
        for(int i=0;i<4;++i){
             scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z);
        }
        double rea=pointMuti(p[1]-p[0],cross(p[2]-p[0],p[3]-p[0]));
        if(!rea){
            puts("Yes");
        }else{
            puts("No");
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/viscu/article/details/71057181