E - The Tower HDU - 6559
#include <set> #include <map> #include <deque> #include <queue> #include <stack> #include <cmath> #include <ctime> #include <bitset> #include <cstdio> #include <string> #include <vector> #include <cstdlib> #include <cstring> #include <cassert> #include <iostream> #include <algorithm> #include <unordered_map> using namespace std; const int INF=0x3f3f3f3f; typedef long long LL; typedef pair<LL, LL> pLL; typedef pair<LL, int> pLi; typedef pair<int, LL> pil;; typedef pair<int, int> pii; typedef unsigned long long uLL; //这道题没有考虑加速度,且是在塔外面往塔上跳 //长时间未敲代码,double的输入输出都不会了
//既然一定跳到圆锥上,那么可以假设这点是(x,y,z),然后根据圆锥的截面建立方程x*x+y*y=r1*r1
double x,y,z,vx,vy,vz,r,h; bool check(double t) { double x1=x+vx*t; double y1=y+vy*t; double z1=z+vz*t; //printf("%f\n",z1); if(z1<0||z1>h)return false; return (x1*x1+y1*y1-(1-z1/h)*(1-z1/h)*r*r)<=1e-8; } int main() { int t; scanf("%d",&t); int kase=0; while(t--) { scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&r,&h,&x,&y,&z,&vx,&vy,&vz); // printf("%f %f %f %f %f %f %f %f\n",r,h,x,y,z,vx,vy,vz); double a=vz*vz*r*r/(h*h)-vx*vx-vy*vy; double b=2*z*vz*r*r/(h*h)-2*vz*r*r/h-2*x*vx-2*y*vy; double c=r*r*((h-z)/h)*((h-z)/h)-x*x-y*y; //printf("%f %f %f\n",a,b,c); double t1=(-b+sqrt(b*b-4*a*c))/(2*a); double t2=(-b-sqrt(b*b-4*a*c))/(2*a); // // printf("%f ==== %f\n",t1,t2); double ans=INF; if(check(t1))ans=min(ans,t1); if(check(t2))ans=min(ans,t2); printf("Case %d: %.10f\n",++kase,ans); } return 0; }