E - The Tower(2018CCPC吉林赛区)(计算几何)

E - The Tower(2018CCPC吉林赛区)(计算几何)

Time limit:1000 ms
Memory limit:262144 kB
judge:
HDU 6559
vjudge

Problem 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 ( x 0 , y 0 , z 0 ) (x_0, y_0, z_0) (x0,y0,z0) with velocity ( v x , v y , v z ) (v_x, v_y, v_z) (vx,vy,vz). What time will they collide? Here is the cone tower.
在这里插入图片描述

Input

The first line contains testcase number T ( T ≤ 1000 ) T (T ≤ 1000) T(T1000), For each testcase the first line contains spaceseparated real numbers r r r and h ( 1 ≤ r , h ≤ 1000 ) h (1 ≤ r, h ≤ 1000) h(1r,h1000) — the base radius and the cone height correspondingly.
For each testcase the second line contains three real numbers x 0 , y 0 , z 0 ( 0 ≤ ∣ x 0 ∣ , ∣ y 0 ∣ , z 0 ≤ 1000 ) x_0, y_0, z_0 (0 ≤ |x_0|, |y_0|, z_0 ≤ 1000) x0,y0,z0(0x0,y0,z01000). For each testcase the third line contains three real numbers v x , v y , v z ( 1 ≤ v 2 x + v 2 y + v 2 z ≤ 3 × 1 0 6 ) v_x, v_y, v_z (1 ≤ v_2^x + v_2^y + v_2^z ≤ 3 × 10^6) vx,vy,vz(1v2x+v2y+v2z3×106). It is guaranteed that at time 0 the point is outside the cone and they will always collide.

Output

For each testcase print Case i : and then print the answer in one line, with absolute or relative error not exceeding 1 0 − 6 10^{−6} 106

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

题意

给你一个圆锥,其底面的圆心的坐标是 ( 0 , 0 , 0 ) (0,0,0) (0,0,0),再给你一个圆锥外的点的坐标和初速度,且保证他们俩一定会相撞,问你相撞的时间。(点在 y y y 轴上方)。

题解

列方程,联立后求解。

因为点在 y y y 轴上方,所以联立方程时不必考虑圆锥的底面。

列出圆锥上表面的表达式:
{ x 2 + y 2 = R 2 r − R r = z h \left\{\begin{array}{cc} x^2+y^2=R^2\\ \frac{r-R}{r}=\frac{z}{h} \end{array}\right. { x2+y2=R2rrR=hz
列出点的轨迹方程:
{ x = x 0 + v x t y = y 0 + v y t z = z 0 + v z t \left\{\begin{array}{ll} x=x_0+v_xt\\ y=y_0+v_yt\\ z=z_0+v_zt \end{array}\right. x=x0+vxty=y0+vytz=z0+vzt
联立消元:
( x 0 + v x t ) 2 + ( y 0 + v x t ) 2 = [ r − r ( z 0 + v z t ) h ] 2 (x_0+v_xt)^2+(y_0+v_xt)^2=[r-\frac{r(z_0+v_zt)}{h}]^2 (x0+vxt)2+(y0+vxt)2=[rhr(z0+vzt)]2
化简后为:
( v x 2 + v y 2 − r 2 v z 2 h 2 ) t 2 + ( 2 x 0 v x + 2 y 0 v y + 2 r 2 v z h − 2 r 2 z 0 v z h 2 ) t + x 0 2 + y 0 2 − r 2 + 2 r 2 z 0 h − r 2 z 0 2 h 2 = 0 (v_x^2+v_y^2-\frac{r^2v_z^2}{h^2})t^2+(2x_0v_x+2y_0v_y+\frac{2r^2v_z}{h}-\frac{2r^2z_0v_z}{h^2})t+x_0^2+y_0^2-r^2+\frac{2r^2z_0}{h}-\frac{r^2z_0^2}{h^2}=0 (vx2+vy2h2r2vz2)t2+(2x0vx+2y0vy+h2r2vzh22r2z0vz)t+x02+y02r2+h2r2z0h2r2z02=0
再次化简后得:
a t 2 + b t + c = 0 at^2+bt+c=0 at2+bt+c=0
其中
{ a = v x 2 + v y 2 − r 2 v z 2 h 2 b = 2 x 0 v x + 2 y 0 v y + 2 r 2 v z h − 2 r 2 z 0 v z h 2 c = x 0 2 + y 0 2 − r 2 + 2 r 2 z 0 h − r 2 z 0 2 h 2 \left\{\begin{array}{ll} a=v_x^2+v_y^2-\frac{r^2v_z^2}{h^2}\\ b=2x_0v_x+2y_0v_y+\frac{2r^2v_z}{h}-\frac{2r^2z_0v_z}{h^2}\\ c=x_0^2+y_0^2-r^2+\frac{2r^2z_0}{h}-\frac{r^2z_0^2}{h^2} \end{array}\right. a=vx2+vy2h2r2vz2b=2x0vx+2y0vy+h2r2vzh22r2z0vzc=x02+y02r2+h2r2z0h2r2z02
利用求解公式求出较小的那个值就是答案:
a n s = − b − b 2 − 4 a c 2 a ans=\frac{-b-\sqrt{b^2-4ac}}{2a} ans=2abb24ac

代码

#include <bits/stdc++.h>
using namespace std;

int T;
double r, h, x_0, y_0, z_0, vx, vy, vz;

int main() {
    
    
	while (cin >> T) {
    
    
		for (int i = 1; i <= T; ++i) {
    
    
			scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &r, &h, &x_0, &y_0, &z_0, &vx, &vy, &vz);
			double a = vx * vx + vy * vy - vz * vz*r*r / h / h;
			double b = 2 * x_0 * vx + 2 * y_0 * vy + 2 * r*r*vz / h - 2 * z_0*vz*r*r / h / h;
			double c = x_0 * x_0 + y_0 * y_0 - r * r + 2 * r*r*z_0 / h - r * r*z_0*z_0 / h / h;
			double ans = (-b - sqrt(b*b - 4 * a*c)) / 2 / a;
			printf("Case %d: %.10f\n", i, ans);
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42856843/article/details/105543747
E