题目链接:http://icpc.upc.edu.cn/problem.php?cid=1747&pid=4
题目描述
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
=
x
0
+
v
1
t
y
=
y
0
+
v
2
t
z
=
z
0
+
v
3
t
x
2
+
y
2
r
2
=
(
h
−
z
)
2
h
2
\begin{cases} x=x_{0}+v_{1}t\\ y=y_{0}+v_{2}t\\ z=z_{0}+v_{3}t\\\frac{x^{2}+y^{2}}{r^{2}}=\frac{(h-z)^{2}}{h^{2}}\\ \end{cases}
⎩⎪⎪⎪⎨⎪⎪⎪⎧x=x0+v1ty=y0+v2tz=z0+v3tr2x2+y2=h2(h−z)2
t
t
t即为需要的时间
AC代码
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
using namespace std;
#define io ios::sync_with_stdio(0),cin.tie(0)
#define ms(arr) memset(arr,0,sizeof(arr))
#define mc(a,b) memcpy(a,b,sizeof(b))
#define inf 0x3f3f3f
#define fin freopen("in.txt", "r", stdin)
#define fout freopen("out.txt", "w", stdout)
typedef long long ll;
typedef unsigned long long ULL;
const int mod=1e9+7;
const int N=1e5+7;
int main()
{
// fin;
int t;
double r,h,x,y,z,v1,v2,v3;
scanf("%d",&t);
for(int k=1;k<=t;k++){
scanf("%lf %lf",&r,&h);
scanf("%lf %lf %lf",&x,&y,&z);
scanf("%lf %lf %lf",&v1,&v2,&v3);
double a=h*h*v1*v1+h*h*v2*v2-r*r*v3*v3;
double b=2.0*h*h*x*v1+2.0*h*h*y*v2+2.0*r*r*h*v3-2.0*r*r*z*v3;
double c=2.0*r*r*z*h-r*r*h*h-r*r*z*z+h*h*x*x+h*h*y*y;
double d=b*b-4.0*a*c;
double ans=(-b-sqrt(d))/(2.0*a);
printf("Case %d: %.10f\n",k,ans);
}
return 0;
}