HDU 5206 Four Inages Strategy
2015-10-03 00:44
405 查看
题意:给出三维空间中的4个点 判断能否组成正方形
比赛时直接套的三维几何的版子 判断3个向量中 是否有两个相等 垂直 且和为第三个向量
其实可以算出他们两两之间距离 排个序 看小的四个是否相等(4个边) 和剩下两条对角线相等 且长度为根号2倍的边长 (防止误差可以一直用平方来计算)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#define scnaf scanf
#define cahr char
#define bug puts("bugbugbug");
using namespace std;
typedef long long ll;
const int mod=1000000007;
const int maxn=2000+5;
const int inf=1e9;
const int maxe=200000;
struct Point{
ll x,y,z;
Point(ll x=0,ll y=0,ll z=0):x(x),y(y),z(z){ }
}a[10];
Point operator - (Point a,Point b){ return Point(a.x-b.x,a.y-b.y,a.z-b.z); }
Point operator + (Point a,Point b){ return Point(a.x+b.x,a.y+b.y,a.z+b.z); }
Point operator * (Point a,Point b){ return Point(a.x*b.x+a.y*b.y+a.z*b.z); }
bool operator == (const Point &a,const Point &b) {
return a.x==b.x&&a.y==b.y&&a.z==b.z;
}
Point b,c,d;
ll dis(Point a)
{
return a.x*a.x+a.y*a.y+a.z*a.z;
}
int main()
{
int T_T,test=1;
scanf("%d",&T_T);
while(T_T--)
{
int flag=0;
for(int i=0;i<4;i++)
scanf("%I64d%I64d%I64d",&a[i].x,&a[i].y,&a[i].z);
b=a[1]-a[0];
c=a[2]-a[0];
d=a[3]-a[0];
if(dis(b)==dis(c)&&b+c==d&&b*c==0) flag=1;
else if(dis(b)==dis(d)&&b+d==c&&b*d==0) flag=1;
else if(dis(d)==dis(c)&&d+c==b&&d*c==0) flag=1;
printf("Case #%d: ",test++);
if(flag) puts("Yes");
else puts("No");
}
return 0;
}
比赛时直接套的三维几何的版子 判断3个向量中 是否有两个相等 垂直 且和为第三个向量
其实可以算出他们两两之间距离 排个序 看小的四个是否相等(4个边) 和剩下两条对角线相等 且长度为根号2倍的边长 (防止误差可以一直用平方来计算)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#define scnaf scanf
#define cahr char
#define bug puts("bugbugbug");
using namespace std;
typedef long long ll;
const int mod=1000000007;
const int maxn=2000+5;
const int inf=1e9;
const int maxe=200000;
struct Point{
ll x,y,z;
Point(ll x=0,ll y=0,ll z=0):x(x),y(y),z(z){ }
}a[10];
Point operator - (Point a,Point b){ return Point(a.x-b.x,a.y-b.y,a.z-b.z); }
Point operator + (Point a,Point b){ return Point(a.x+b.x,a.y+b.y,a.z+b.z); }
Point operator * (Point a,Point b){ return Point(a.x*b.x+a.y*b.y+a.z*b.z); }
bool operator == (const Point &a,const Point &b) {
return a.x==b.x&&a.y==b.y&&a.z==b.z;
}
Point b,c,d;
ll dis(Point a)
{
return a.x*a.x+a.y*a.y+a.z*a.z;
}
int main()
{
int T_T,test=1;
scanf("%d",&T_T);
while(T_T--)
{
int flag=0;
for(int i=0;i<4;i++)
scanf("%I64d%I64d%I64d",&a[i].x,&a[i].y,&a[i].z);
b=a[1]-a[0];
c=a[2]-a[0];
d=a[3]-a[0];
if(dis(b)==dis(c)&&b+c==d&&b*c==0) flag=1;
else if(dis(b)==dis(d)&&b+d==c&&b*d==0) flag=1;
else if(dis(d)==dis(c)&&d+c==b&&d*c==0) flag=1;
printf("Case #%d: ",test++);
if(flag) puts("Yes");
else puts("No");
}
return 0;
}
相关文章推荐
- 总结一下最近做的计算几何学到的知识
- csu1503 点到圆弧的距离
- HDU2080 夹角有多大II 几何
- Codeforce Maximal Area Quadrilateral
- [BZOJ1069][SCOI2007][凸包][旋转卡壳]最大土地面积
- poj_2002
- 计算几何
- 两个while循环求凸包 poj2187 poj1113
- 强大的旋转卡壳 POJ 2187 最远点对 POJ 2079点集中面积最大的三角形
- 二分 点集中最近点对、周长最小三角形
- Codeforces Round #230 (Div. 2) C: Blocked Points 水泄不通的点墙
- FZU 2148: Moon Game 四边形的月亮
- 求两圆相交部分面积(C/C++)
- HOJ 13348 Finding Lines 画直线最多点
- Hdu 4609 FFT
- 2015 Multi-University Training Contest 1 Hdu5295 unstable
- 没参加的2015百度之星——数矩形
- 学习笔记: 反演几何
- cf#320 Div.2 Problem C A Problem about Polyline
- nyoj-3-多边形重心问题