THE TOWER【纯数学】

博客围绕一个圆锥碰撞时间问题展开,给出题目描述,包括圆锥的参数及点的初始位置和速度,还有输入输出要求与样例。解题思路是通过解方程组得出碰撞时间t,最后给出了AC代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接: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(hz)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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值