The Tower(ccpc吉林)
http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1005&cid=867
#include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #include<cmath> using namespace std; int main(){ int t; scanf("%d",&t); int sign=1; while(t--){ double r,h; scanf("%lf%lf",&r,&h); double tanx=h/r; double x0,y0,z0,xv,yv,zv; scanf("%lf%lf%lf%lf%lf%lf",&x0,&y0,&z0,&xv,&yv,&zv); double a=xv*xv+yv*yv-zv*zv/(tanx*tanx); double b=2.0*(x0*xv+y0*yv+zv*r/tanx-z0*zv/(tanx*tanx)); double c=x0*x0+y0*y0-r*r+2.0*z0*r/tanx-z0*z0/(tanx*tanx); double fuck=fabs(b*b-4.0*a*c); double ans1=(-b+sqrt(fuck))/(2.0*a); double ans2=(-b-sqrt(fuck))/(2.0*a); double ans; double z1=z0+zv*ans1; double z2=z0+zv*ans2; if(z1<=h&&z1>=0&&z2<=h&&z2>=0){ ans=min(ans1,ans2); } else if(z1<=h&&z1>=0){ ans=ans1; } else ans=ans2; printf("Case %d: %.10lf\n",sign++,ans); } return 0; }