hdu 4741 Save Labman No.004 [2013年杭州ACM网络赛]

// Time 234 ms; Memory 244 K
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

typedef struct point
{
	double x,y,z;
	point(double xx=0,double yy=0,double zz=0):x(xx),y(yy),z(zz){}
}vector;
vector operator - (point a,point b)
{
	return vector(a.x-b.x,a.y-b.y,a.z-b.z);
}
point operator + (point a,vector b)
{
	return point(a.x+b.x,a.y+b.y,a.z+b.z);
}
vector operator * (vector a,double b)
{
	return vector(a.x*b,a.y*b,a.z*b);
}
double dot(vector a,vector b)
{
	return a.x*b.x+a.y*b.y+a.z*b.z;
}
double len(vector a)
{
	return sqrt(dot(a,a));
}
vector cross(vector a,vector b)
{
	return vector(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x);
}
point inter(point a,point b,point c,point d,point e)
{
	point fa=cross(b-a,c-a);
	double t=dot(fa,a-d)/dot(fa,e-d);
	return d+(e-d)*t;
}
vector resize(vector a,double b)
{
	b/=len(a);
	return a*b;
}
point ptol(point o,point a,point b)
{
	point fa=cross(a-o,b-o);
	point vec=cross(b-a,fa);
	return o+resize(vec,len(fa)/len(b-a));
}
void gc(point a,point b,point c,point d,point &p1,point &p2)
{
	point e=d+cross(a-b,c-d);
	p1=inter(c,d,e,a,b);
	p2=ptol(p1,c,d);
}

int main()
{
	int t;
	point a,b,c,d,p,q;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&a.z,&b.x,&b.y,&b.z);
		scanf("%lf%lf%lf%lf%lf%lf",&c.x,&c.y,&c.z,&d.x,&d.y,&d.z);
		gc(a,b,c,d,p,q);
		double l=len(p-q);
		printf("%.6lf\n",l);
		printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n",p.x,p.y,p.z,q.x,q.y,q.z);
	}
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值