2018ccpc吉林 E: THE TOWER (公式)

问题 E: THE TOWER

时间限制: 1 Sec  内存限制: 128 MB  Special Judge
提交: 222  解决: 30
[提交] [状态] [命题人:admin]

题目描述

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

(题意:给出一个底部圆圆心为(0,0,0),半径为r,高为h的圆锥,问起始位置为(x0,y0,z0),方向为(vx,vy,vz)的点撞上圆锥的时间。)

(思路:假设相撞的点为(x,y,z),根据下图的相似三角形,我们可以得出下图中的方程,解方程,加判断即可。)

 

 

#include <bits/stdc++.h>
using namespace std; 
double r,h,x,y,z,vx,vy,vz;  
bool judge(double t)
{
    double xx,yy,zz;
    xx=x+vx*t;
    yy=y+vy*t;
    zz=z+vz*t;
    if(zz>=0&&zz<=h&&(xx*xx+yy*yy)<=r*r)
    {
        return 1;               
    }
    return 0;  
}
int main(void)
{
    int t;
    scanf("%d",&t);
    for(int cas=1;cas<=t;cas++)
    {
        scanf("%lf%lf",&r,&h);
        scanf("%lf%lf%lf%lf%lf%lf",&x,&y,&z,&vx,&vy,&vz);
        double a,b,c;
        a=h*h*vx*vx+h*h*vy*vy-r*r*vz*vz;
        b=2*h*h*vx*x+2*h*h*vy*y+2*r*r*h*vz-2*r*r*z*vz;
        c=h*h*x*x+h*h*y*y-h*h*r*r-r*r*z*z+2*r*r*h*z;
        double ht=b*b-4*a*c;
        double t1=(sqrt(ht)-b)/(2.0*a);
        double t2=-1.0*(sqrt(ht)+b)/(2.0*a);
        double t=1e18;
        if(judge(t1))
            t=min(t,t1);
        if(judge(t2))
            t=min(t,t2);
        printf("Case %d: ",cas);
        printf("%.10f\n",t);
    }
    return 0;
     
}

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值