HDU5572 An Easy Physics Problem 【计算几何】

来源:互联网 发布:apache ant 1.9.3下载 编辑:程序博客网 时间:2024/06/05 18:19
An Easy Physics ProblemTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2113    Accepted Submission(s): 410Problem DescriptionOn an infinite smooth table, there's a big round fixed cylinder and a little ball whose volume can be ignored.Currently the ball stands still at point A, then we'll give it an initial speed and a direction. If the ball hits the cylinder, it will bounce back with no energy losses.We're just curious about whether the ball will pass point B after some time.InputFirst line contains an integer T, which indicates the number of test cases.Every test case contains three lines.The first line contains three integers Ox, Oy and r, indicating the center of cylinder is (Ox,Oy) and its radius is r.The second line contains four integers Ax, Ay, Vx and Vy, indicating the coordinate of A is (Ax,Ay) and the initial direction vector is (Vx,Vy).The last line contains two integers Bx and By, indicating the coordinate of point B is (Bx,By).⋅ 1 ≤ T ≤ 100.⋅ |Ox|,|Oy|≤ 1000.1 ≤ r ≤ 100.⋅ |Ax|,|Ay|,|Bx|,|By|≤ 1000. ⋅ |Vx|,|Vy|≤ 1000.⋅ Vx≠0 or Vy≠0.⋅ both A and B are outside of the cylinder and they are not at same position.OutputFor every test case, you should output "Case #x: y", where x indicates the case number and counts from 1. y is "Yes" if the ball will pass point B after some time, otherwise y is "No".Sample Input20 0 12 2 0 1-1 -10 0 1-1 2 1 -11 2Sample OutputCase #1: NoCase #2: YesSource2015ACM/ICPC亚洲区上海站-重现赛(感谢华东理工)

情况有好几种
如果将整个图旋转一下 ,让(Vx,Vy)旋转到X轴正方向 ,处理起来就简单很多
当A能射中B:

①A直接射到B上:
这种情况ABxABA,B线y=Ay
Ay==ByAx<Bx(Ox<Ax||Ox>Bx||Ay>Oy+r||Ay<Oyr)

②A射到圆上,且沿着反方向反弹,射中B
Ay==By==OyAx>BxOx>Ax

other:
ACACC线α,A线α
B线AC线BC线
dis=BC,BD=(Cx+dis,Cy)线线BD线


#include<iostream>#include<stdlib.h>#include<stdio.h>#include<string>#include<vector>#include<deque>#include<queue>#include<algorithm>#include<set>#include<map>#include<stack>#include<time.h>#include<math.h>#include<list>#include<cstring>#include<fstream>#include<queue>#include<sstream>//#include<memory.h>using namespace std;#define ll long long#define ull unsigned long long#define pii pair<int,int>#define INF 1000000007#define pll pair<ll,ll>#define pid pair<int,double>const int inf=1e9+7;const double EPS=1e-7;struct P{    double x,y;    double operator*(const P&p){//点乘        double ans=x*p.x+y*p.y;        return ans;    }    double crossProd(const P&p){//叉乘        return x*p.y-y*p.x;    }    double mod(){        return sqrt(x*x+y*y);    }    void roate(double angle){//逆时针旋转angle度 angle=x*PI        double tx=x*cos(angle)-y*sin(angle);        double ty=y*cos(angle)+x*sin(angle);        x=tx;        y=ty;    }    double distance(const P&p){        double tmp=(p.x-x)*(p.x-x)+(p.y-y)*(p.y-y);        return sqrt(tmp);    }}a,b,o,v;istream&operator>>(istream&in,P&p){    in>>p.x>>p.y;    return in;}int r;bool slove(){    P vec={1,0};    double cosVal=vec*v/(vec.mod()*v.mod());    double angle=acos(cosVal);    if(v.crossProd(vec)<EPS){        angle=-angle;    }    a.roate(angle);    b.roate(angle);    o.roate(angle);    if(fabs(a.y-b.y)<EPS){        if(b.x<a.x){            if(o.x>a.x&&fabs(o.y-a.y)<EPS){                return true;            }            return false;        }        if(a.x<=o.x&&o.x<=b.x){            if(o.y-r<=a.y+EPS&&a.y<=o.y+r+EPS){                return false;            }        }        return true;    }    double ta=1;    double tb=-2.0*o.x;    double tc=o.x*o.x+a.y*a.y-2*o.y*a.y+o.y*o.y-r*r;    double dt=tb*tb-4.0*ta*tc;    if(dt<0){        return false;    }    P c;    c.x=(-tb-sqrt(dt))/(2.0*ta);    c.y=a.y;    double k_co=(c.y-o.y)/(c.x-o.x);    double k=-1.0/k_co;    double dis=b.distance(c);    P d;    d.x=c.x+dis;    d.y=c.y;    P mid={(b.x+d.x)/2.0,(b.y+d.y)/2.0};    return fabs(mid.y-c.y-k*(mid.x-c.x))<EPS;}int main(){    //freopen("/home/lu/Documents/r.txt","r",stdin);    //freopen("/home/lu/Documents/w.txt","w",stdout);    int T;    scanf("%d",&T);    for(int t=1;t<=T;++t){        cin>>o>>r>>a>>v>>b;        printf("Case #%d: %s\n",t,slove()?"Yes":"No");    }    return 0;}
0 0
原创粉丝点击