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

  • Post author:
  • Post category:其他



原题地址

题目描述

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;
}



版权声明:本文为zhouchenghao123原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。