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

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

大家好,我是讯享网,很高兴认识大家。

问题 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. Case 2: 0. 

(题意:给出一个底部圆圆心为(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; }

 

小讯
上一篇 2025-03-12 19:39
下一篇 2025-03-01 14:53

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/121261.html