您的位置:首页 > 其它

51nod 1265 四点共面 (水题)

2015-12-19 18:19 155 查看
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

思路:可以由4个点构成3个向量,3个向量共面的充要条件是向量为a,b,c,存在实数x,y,z不全为零,使得xa+yb+zc=0。转化为线性代数的3个向量线性相关的行列式为0。

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define inf 0x3f3f3f3f

int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int x1,x2,x3,x4,y1,y2,y3,y4,z1,z2,z3,z4;
int t;
int r1,r2,r3,r4,r5,r6,r7,r8,r9;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&x1,&y1,&z1);
scanf("%d%d%d",&x2,&y2,&z2);
scanf("%d%d%d",&x3,&y3,&z3);
scanf("%d%d%d",&x4,&y4,&z4);
r1=x1-x2; r2=y1-y2; r3=z1-z2;
r4=x1-x3; r5=y1-y3; r6=z1-z3;
r7=x1-x4; r8=y1-y4; r9=z1-z4;
if( r1*r5*r9+r2*r6*r7+r3*r4*r8-r3*r5*r7-r2*r4*r9-r1*r6*r8 == 0 )
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: