• 51Nod1265 四点共面


    Problem

    给出三维空间上的四个点(点与点的位置均不相同),判断这4个点是否在同一个平面内(4点共线也算共面)。如果共面,输出"Yes",否则输出"No"。

    Solution

    叉积。。。

    Code

    #include<stdio.h>
    #include<set>
    #include<iostream>
    #include<algorithm>
    #include<cmath>
    #include<cstring>
    #define mem(ss) memset(ss,0,sizeof(ss))
    #define rep(d, s, t) for(int d=s;d<=t;d++)
    #define rev(d, s, t) for(int d=s;d>=t;d--)
    typedef long long ll;
    typedef long double ld;
    typedef double db;
    const ll mod = 1e9+7;
    const int N = 1e4 + 10;
    #define io_opt ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
    const int INF = 1e8;
    using namespace std;
    struct Vector{
        int x,y,z;
        Vector(){
            x=0,y=0,z=0;
        };
    };
    struct Point{
        int x,y,z;
        Point(){
            x=0,y=0,z=0;
        }
        void Input(){
            cin>>x>>y>>z;
        }
    };
    Vector cromul(Vector a1,Vector a2){
        Vector tmp;
        tmp.x=a1.y*a2.z-a1.z*a2.y;
        tmp.y=a1.z*a2.x-a1.x*a2.z;
        tmp.z=a1.x*a2.y-a1.y*a2.x;
        return tmp;
    }
    Vector ptv(Point a1,Point a2){
        Vector tmp;
        tmp.x=a2.x-a1.x;
        tmp.y=a2.y-a1.y;
        tmp.z=a2.z-a1.z;
        return tmp;
    }
    int pmul(Vector a1,Vector a2){
        return a1.x*a2.x+a1.y*a2.y+a1.z*a2.z;
    }
    Point p[6];
    Vector v[10];
    int T;
    int main() {
        io_opt;
        cin>>T;
        while(T--){
            for(int i=1;i<=4;i++){
                p[i].Input();
            }
            v[1]=ptv(p[1],p[2]);
            v[2]=ptv(p[1],p[3]);
            v[3]=ptv(p[1],p[4]);
            v[4]=cromul(v[1],v[2]);
            if(pmul(v[3],v[4])==0){
                cout<<"Yes
    ";
            }
            else{
                cout<<"No
    ";
            }
        }
        return 0;
    }
    
  • 相关阅读:
    文章块引用模版
    悬停工具提示
    各个知识点
    Github Fork 缎带.html
    css重置样式
    暗灰色的圆形按钮.html
    css中的居中的方法
    display:table的几个用法 块级子元素垂直居中
    <meta>标签中http-equiv属性的属性值X-UA-Compatible详解
    jQuery难学是因为什么?
  • 原文地址:https://www.cnblogs.com/sz-wcc/p/11664041.html
Copyright © 2020-2023  润新知