标签:位置 typedef ios rev eof problem using type double
给出三维空间上的四个点(点与点的位置均不相同),判断这4个点是否在同一个平面内(4点共线也算共面)。如果共面,输出"Yes",否则输出"No"。
叉积。。。
#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\n";
}
else{
cout<<"No\n";
}
}
return 0;
}
标签:位置 typedef ios rev eof problem using type double
原文地址:https://www.cnblogs.com/sz-wcc/p/11664041.html