HDU4973 【几何。】
题意:
给你一个以原点为圆心的两个圆,一个大圆,一个小圆,然后给你一个硬币和他的速度,问你经过大圆的时间;
思路:
直接杠。。
然后wa的怀疑人生,后面wa在了速度的方向,如果我说一个点在两个圆的左上方,那么速度也是左上方,那么就是0;
其他都还简单;
贴一发比赛时的挫代码。。。
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> #include <queue> #include <stack> using namespace std; const int MAX=210; const double eps=1e-3; int n,m; int main() { int i,j,t; double Rm,r,R,x,y,vx,vy; while(~scanf("%lf%lf%lf%lf%lf%lf%lf",&Rm,&R,&r,&x,&y,&vx,&vy)) { double x1,x2,y1,y2,x3,x4,y3,y4; double Rmr=(Rm+r)*(Rm+r); double Rr=(r+R)*(r+R); double a1=vx*vx+vy*vy; double b1=2*(vx*x+vy*y); double c1=x*x+y*y-Rr; double a2=vx*vx+vy*vy; double b2=2*(vx*x+vy*y); double c2=x*x+y*y-Rmr; double aa=vx*vx+vy*vy; // 碰不到大圆 if(b1*b1-4*a1*c1<=eps) { puts("0.000"); } else { double time1,time2; double dt1=sqrt(b1*b1-4*a1*c1); time1=(-b1+dt1)/2.0/a1; time2=(-b1-dt1)/2.0/a1; if(time1<=eps)// 碰不到大圆 时间一定是正的 { puts("0.000"); continue; } x1=time1*vx+x; y1=time1*vy+y; x2=time2*vx+x; y2=time2*vy+y; //只经过大圆 if(b2*b2-4*a2*c2<=eps) { double ans=((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))/aa; printf("%.6lf\n",sqrt(ans)); } else //经过小圆和大圆 { double dt2=sqrt(b2*b2-4*a2*c2); double time3,time4; time3=(-b2+dt2)/2.0/a2; time4=(-b2-dt2)/2.0/a2; x3=time3*vx+x; y3=time3*vy+y; x4=time4*vx+x; y4=time4*vy+y; double ans1=((x1-x4)*(x1-x4)+(y1-y4)*(y1-y4))/aa; double ans2=((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3))/aa; double ans=min(ans1,ans2); printf("%.6lf\n",2*sqrt(ans)); } } } return 0; } /* */