问题 E: THE TOWER (数学,计算几何)

原题地址 

题目描述

The Tower shows atall tower perched on the top of a rocky mountain. Lightning strikes, setting the building alight, and two people leap frnm the windows, head first and arms outstretched. 
It is a scene of chaos and destruction.
There is a cone tower with base center at (0, 0, 0), base radius r and apex (0, 0, h) . At time 0 , a point located at ( x0 ,y0, z0) with velocity (vx,vy,vz). What time will they collide? Here is the cone tower.

 

输入

The first line contains testcase number T (T≤1000), For each testcase the first line contains spaceseparated real numbers rand h (1≤r,h≤1000) the base radius and the cone height correspondingly.
For each testcase the second line contains three real numbers x0 ,y0, z0 (0≤|x0|,|y0|,z0≤1000). For each testcase the third line contains three real numbers vx,vy,vx (). It is guaranteed that at time 0 the point is outside the cone and they will always collide.

 

输出

For each testcase print Case i: and then print the answer in one line, with absolute or relative error not exceeding 10-6

 

样例输入

复制样例数据

2
1 2
1 1 1
-1.5 -1.5 -0.5
1 1
1 1 1
-1 -1 -1

样例输出

Case 1: 0.3855293381
Case 2: 0.5857864376
/*
	x=x0+vx*t;
	y=y0+vy*t;
	z=z0+vz*t;
	sqrt(x*x+y*y)/r=(h-z)/h;
*/
#include<iostream>
#include<cmath>
using namespace std;
double x,y,z,vx,vy,vz;
double r,h;
int main()
{
	int t;

	cin>>t;

	for(int k=1; k<=t; k++)
	{
		cin>>r>>h;
		cin>>x>>y>>z;
		cin>>vx>>vy>>vz;
		double a=h*h*vx*vx+h*h*vy*vy-r*r*vz*vz;
		double b=2*(h*h*x*vx+h*h*y*vy+h*vz*r*r-z*vz*r*r);
		double c=x*x*h*h+y*y*h*h-(z-h)*(z-h)*r*r;
		double res1=(-b+sqrt(b*b-4*a*c))*1.0/(2*a);
		double res2=(-b-sqrt(b*b-4*a*c))*1.0/(2*a);
		double res=999999999999.999;
		if(res1>=0&&(z+vz*res1)>=0&&(z+vz*res1)<=h)
			res=min(res,res1);
		if(res2>=0&&(z+vz*res2)>=0&&(z+vz*res2)<=h)
			res=min(res,res2);
		printf("Case %d: %.12f\n",k,res);
	}
	return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值