Description:

The Tower shows a tall tower perched on the top of a rocky mountain. Lightning strikes, setting the building alight, and two people leap from 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 (x0x0, y0y0, z0z0) with velocity (vxvx, vyvy, vzvz). What time will they collide? Here is the cone tower. 

HDU - 6559 The Tower (计算几何)_ide

Input

The first line contains testcase number TT (TT ≤ 1000), For each testcase the first line contains spaceseparated real numbers rr and hh (1 ≤ rr, hh ≤ 1000) — the base radius and the cone height correspondingly. 
For each testcase the second line contains three real numbers x0x0, y0y0, z0z0 (0 ≤ |x0x0|, |y0y0|, z0z0 ≤ 1000). For each testcase the third line contains three real numbers vxvx, vyvy, vzvz (1 ≤ v2xvx2 + v2yvy2 + v2zvz2 ≤ 3 × 106106). It is guaranteed that at time 0 the point is outside the cone and they will always collide.

Output

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

Sample Input

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

Sample Output

Case 1: 0.3855293381 Case 2: 0.5857864376

给出一个圆锥体的半径和高,圆锥的地面圆心在坐标轴原点,又给出了一个质点的坐标和移动速度,求最短经过多长时间可以使质点和圆锥相交。

 

设ttt为碰撞时间,建立圆锥曲面和运动轨迹的方程,联立方程解。
则运动轨迹方程组为:

HDU - 6559 The Tower (计算几何)_#include_02


圆锥曲面方程组为:

HDU - 6559 The Tower (计算几何)_#include_03

化简然后求t

AC代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdlib.h>
#include<queue>
#include<map>
#include<iomanip>
#include<math.h>
using namespace std;
double deta(double a,double b,double c)
{
double ans=b*b-4*a*c;
ans=sqrt(ans);
return ans;
}
int main()
{
int t,Case=0;
cin>>t;
double r,h;
double x0,y0,z0,vx,vy,vz;
while(t--)
{
cin>>r>>h;
cin>>x0>>y0>>z0;
cin>>vx>>vy>>vz;
double a,b,c;
a=vx*vx+vy*vy-vz*vz*r*r/(h*h);
b=2*x0*vx+2*y0*vy+2*r*r*vz/h-2*z0*vz*r*r/(h*h);
c=x0*x0+y0*y0-r*r+2*r*r*z0/h-r*r*z0*z0/(h*h);
double t2=(-b-deta(a,b,c))/(2*a);
printf("Case %d: %.10lf\n",++Case,t2);
}

return 0;
}